

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
  "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">


<html xmlns="http://www.w3.org/1999/xhtml">
  <head>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
    
    <title>scitools.TkGUI &mdash; SciTools 0.9.0 documentation</title>
    
    <link rel="stylesheet" href="../../_static/default.css" type="text/css" />
    <link rel="stylesheet" href="../../_static/pygments.css" type="text/css" />
    
    <script type="text/javascript">
      var DOCUMENTATION_OPTIONS = {
        URL_ROOT:    '../../',
        VERSION:     '0.9.0',
        COLLAPSE_INDEX: false,
        FILE_SUFFIX: '.html',
        HAS_SOURCE:  true
      };
    </script>
    <script type="text/javascript" src="../../_static/jquery.js"></script>
    <script type="text/javascript" src="../../_static/underscore.js"></script>
    <script type="text/javascript" src="../../_static/doctools.js"></script>
    <script type="text/javascript" src="http://cdn.mathjax.org/mathjax/latest/MathJax.js?config=TeX-AMS-MML_HTMLorMML"></script>
    <link rel="top" title="SciTools 0.9.0 documentation" href="../../index.html" />
    <link rel="up" title="Module code" href="../index.html" /> 
  </head>
  <body>
    <div class="related">
      <h3>Navigation</h3>
      <ul>
        <li class="right" style="margin-right: 10px">
          <a href="../../genindex.html" title="General Index"
             accesskey="I">index</a></li>
        <li class="right" >
          <a href="../../py-modindex.html" title="Python Module Index"
             >modules</a> |</li>
        <li class="right" >
          <a href="../../np-modindex.html" title="Python Module Index"
             >modules</a> |</li>
        <li><a href="../../index.html">SciTools 0.9.0 documentation</a> &raquo;</li>
          <li><a href="../index.html" accesskey="U">Module code</a> &raquo;</li> 
      </ul>
    </div>  

    <div class="document">
      <div class="documentwrapper">
        <div class="bodywrapper">
          <div class="body">
            
  <h1>Source code for scitools.TkGUI</h1><div class="highlight"><pre>
<span class="sd">&quot;&quot;&quot;</span>
<span class="sd">Module with functions and classes used in the GUI chapters of</span>
<span class="sd">the book &quot;Python Scripting for Computational Science&quot;.</span>
<span class="sd">&quot;&quot;&quot;</span>
<span class="c"># NOTE: This file merges the previous modules</span>
<span class="c"># CanvasCoords, FunctionSelector, DrawFunction, FuncDependenceViz,</span>
<span class="c"># ParameterInterface</span>
<span class="c">#</span>

<span class="kn">import</span> <span class="nn">Tkinter</span><span class="o">,</span> <span class="nn">os</span>
<span class="kn">from</span> <span class="nn">scitools.misc</span> <span class="kn">import</span> <span class="n">import_module</span>
<span class="n">Pmw</span> <span class="o">=</span> <span class="n">import_module</span><span class="p">(</span><span class="s">&#39;Pmw&#39;</span><span class="p">)</span>

<div class="viewcode-block" id="DrawFunction"><a class="viewcode-back" href="../../TkGUI.html#scitools.TkGUI.DrawFunction">[docs]</a><span class="k">class</span> <span class="nc">DrawFunction</span><span class="p">:</span>
    <span class="sd">&quot;&quot;&quot;</span>
<span class="sd">    Interactive drawing of y=f(x) functions.</span>
<span class="sd">    The drawing takes place in a Pmw.Blt.Graph widget.</span>
<span class="sd">    &quot;&quot;&quot;</span>
<div class="viewcode-block" id="DrawFunction.__init__"><a class="viewcode-back" href="../../TkGUI.html#scitools.TkGUI.DrawFunction.__init__">[docs]</a>    <span class="k">def</span> <span class="nf">__init__</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">xcoor</span><span class="p">,</span> <span class="n">parent</span><span class="p">,</span>
                 <span class="n">ymin</span><span class="o">=</span><span class="mf">0.0</span><span class="p">,</span> <span class="n">ymax</span><span class="o">=</span><span class="mf">1.0</span><span class="p">,</span>
                 <span class="n">width</span><span class="o">=</span><span class="mi">500</span><span class="p">,</span> <span class="n">height</span><span class="o">=</span><span class="mi">200</span><span class="p">,</span>
                 <span class="n">curvename</span><span class="o">=</span><span class="s">&#39; &#39;</span><span class="p">,</span> <span class="n">ylabel</span><span class="o">=</span><span class="s">&#39;&#39;</span><span class="p">,</span> <span class="n">xlabel</span><span class="o">=</span><span class="s">&#39;&#39;</span><span class="p">,</span>
                 <span class="n">curvecolor</span><span class="o">=</span><span class="s">&#39;green&#39;</span><span class="p">,</span> <span class="n">curvewidth</span><span class="o">=</span><span class="mi">4</span><span class="p">,</span>
                 <span class="n">yrange_widgets</span><span class="o">=</span><span class="bp">True</span><span class="p">):</span>
        <span class="sd">&quot;&quot;&quot;</span>
<span class="sd">        Interactive drawing of a function.</span>

<span class="sd">        xcoor           grid points (on the x axsis) for interpolation</span>
<span class="sd">        parent          parent widget</span>
<span class="sd">        ymin, ymax      initial extent of the y axis</span>
<span class="sd">        width, height   size of widget</span>
<span class="sd">        curvename       name of function to be drawn</span>
<span class="sd">        xlabel, ylabel  labels on the axis</span>
<span class="sd">        curvecolor      color of the drawn curve</span>
<span class="sd">        curvewidth      line thickness of the drawn curve</span>
<span class="sd">        yrange_widgets  True: add text entries for range of y axis</span>

<span class="sd">        These parameters, except for parent and yrange_widgets,</span>
<span class="sd">        can also be set as keyword arguments in the configure method.</span>
<span class="sd">        &quot;&quot;&quot;</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">master</span> <span class="o">=</span> <span class="n">parent</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">top</span> <span class="o">=</span> <span class="n">Tkinter</span><span class="o">.</span><span class="n">Frame</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">master</span><span class="p">)</span>
        <span class="c"># packed in self.pack(); the user can then place this</span>
        <span class="c"># DrawFunction wherever it is desired in a big GUI</span>

        <span class="n">frame1</span> <span class="o">=</span> <span class="n">Tkinter</span><span class="o">.</span><span class="n">Frame</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">top</span><span class="p">);</span>  <span class="n">frame1</span><span class="o">.</span><span class="n">pack</span><span class="p">(</span><span class="n">side</span><span class="o">=</span><span class="s">&#39;top&#39;</span><span class="p">)</span>
        <span class="k">if</span> <span class="n">yrange_widgets</span><span class="p">:</span>
            <span class="n">column1</span> <span class="o">=</span> <span class="n">Tkinter</span><span class="o">.</span><span class="n">Frame</span><span class="p">(</span><span class="n">frame1</span><span class="p">)</span>
            <span class="n">column1</span><span class="o">.</span><span class="n">pack</span><span class="p">(</span><span class="n">side</span><span class="o">=</span><span class="s">&#39;left&#39;</span><span class="p">)</span>
            <span class="k">if</span> <span class="n">ylabel</span><span class="p">:</span>  <span class="n">yl</span> <span class="o">=</span> <span class="n">ylabel</span>
            <span class="k">else</span><span class="p">:</span>       <span class="n">yl</span> <span class="o">=</span> <span class="s">&#39;y&#39;</span>
            <span class="bp">self</span><span class="o">.</span><span class="n">ymin_widget</span> <span class="o">=</span> <span class="n">Pmw</span><span class="o">.</span><span class="n">EntryField</span><span class="p">(</span><span class="n">column1</span><span class="p">,</span>
                <span class="n">labelpos</span><span class="o">=</span><span class="s">&#39;n&#39;</span><span class="p">,</span> <span class="n">label_text</span><span class="o">=</span><span class="n">yl</span><span class="o">+</span><span class="s">&#39; min&#39;</span><span class="p">,</span>
                <span class="n">entry_width</span><span class="o">=</span><span class="mi">6</span><span class="p">,</span> <span class="n">command</span><span class="o">=</span><span class="bp">self</span><span class="o">.</span><span class="n">__ymin</span><span class="p">)</span>
            <span class="bp">self</span><span class="o">.</span><span class="n">ymin_widget</span><span class="o">.</span><span class="n">pack</span><span class="p">(</span><span class="n">side</span><span class="o">=</span><span class="s">&#39;top&#39;</span><span class="p">,</span><span class="n">padx</span><span class="o">=</span><span class="mi">2</span><span class="p">,</span><span class="n">pady</span><span class="o">=</span><span class="mi">2</span><span class="p">)</span>

            <span class="bp">self</span><span class="o">.</span><span class="n">ymax_widget</span> <span class="o">=</span> <span class="n">Pmw</span><span class="o">.</span><span class="n">EntryField</span><span class="p">(</span><span class="n">column1</span><span class="p">,</span>
                <span class="n">labelpos</span><span class="o">=</span><span class="s">&#39;n&#39;</span><span class="p">,</span> <span class="n">label_text</span><span class="o">=</span><span class="n">yl</span><span class="o">+</span><span class="s">&#39; max&#39;</span><span class="p">,</span>
                <span class="n">entry_width</span><span class="o">=</span><span class="mi">6</span><span class="p">,</span> <span class="n">command</span><span class="o">=</span><span class="bp">self</span><span class="o">.</span><span class="n">__ymax</span><span class="p">)</span>
            <span class="bp">self</span><span class="o">.</span><span class="n">ymax_widget</span><span class="o">.</span><span class="n">pack</span><span class="p">(</span><span class="n">side</span><span class="o">=</span><span class="s">&#39;top&#39;</span><span class="p">,</span><span class="n">padx</span><span class="o">=</span><span class="mi">2</span><span class="p">,</span><span class="n">pady</span><span class="o">=</span><span class="mi">2</span><span class="p">)</span>
            <span class="n">Pmw</span><span class="o">.</span><span class="n">alignlabels</span><span class="p">([</span><span class="bp">self</span><span class="o">.</span><span class="n">ymin_widget</span><span class="p">,</span><span class="bp">self</span><span class="o">.</span><span class="n">ymax_widget</span><span class="p">])</span>

        <span class="bp">self</span><span class="o">.</span><span class="n">g</span> <span class="o">=</span> <span class="n">Pmw</span><span class="o">.</span><span class="n">Blt</span><span class="o">.</span><span class="n">Graph</span><span class="p">(</span><span class="n">frame1</span><span class="p">,</span>
                               <span class="n">width</span><span class="o">=</span><span class="n">width</span><span class="p">,</span> <span class="n">height</span><span class="o">=</span><span class="n">height</span><span class="p">)</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">g</span><span class="o">.</span><span class="n">pack</span><span class="p">(</span><span class="n">side</span><span class="o">=</span><span class="s">&#39;left&#39;</span><span class="p">,</span> <span class="n">expand</span><span class="o">=</span><span class="mi">1</span><span class="p">,</span> <span class="n">fill</span><span class="o">=</span><span class="s">&#39;both&#39;</span><span class="p">)</span>

        <span class="k">if</span> <span class="n">yrange_widgets</span><span class="p">:</span>
            <span class="bp">self</span><span class="o">.</span><span class="n">set_yaxis</span><span class="p">(</span><span class="n">ymin</span><span class="p">,</span> <span class="n">ymax</span><span class="p">)</span>

        <span class="bp">self</span><span class="o">.</span><span class="n">configure</span><span class="p">(</span><span class="n">xcoor</span><span class="o">=</span><span class="n">xcoor</span><span class="p">,</span> <span class="n">width</span><span class="o">=</span><span class="n">width</span><span class="p">,</span> <span class="n">height</span><span class="o">=</span><span class="n">height</span><span class="p">,</span>
                       <span class="n">curvename</span><span class="o">=</span><span class="n">curvename</span><span class="p">,</span> <span class="n">curvecolor</span><span class="o">=</span><span class="n">curvecolor</span><span class="p">,</span>
                       <span class="n">curvewidth</span><span class="o">=</span><span class="n">curvewidth</span><span class="p">,</span>
                       <span class="n">xlabel</span><span class="o">=</span><span class="n">xlabel</span><span class="p">,</span> <span class="n">ylabel</span><span class="o">=</span><span class="n">ylabel</span><span class="p">)</span>

        <span class="bp">self</span><span class="o">.</span><span class="n">g</span><span class="o">.</span><span class="n">grid_on</span><span class="p">()</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">g</span><span class="o">.</span><span class="n">bind</span><span class="p">(</span><span class="s">&#39;&lt;ButtonPress&gt;&#39;</span><span class="p">,</span>   <span class="bp">self</span><span class="o">.</span><span class="n">mouse_down</span><span class="p">)</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">g</span><span class="o">.</span><span class="n">bind</span><span class="p">(</span><span class="s">&#39;&lt;ButtonRelease&gt;&#39;</span><span class="p">,</span> <span class="bp">self</span><span class="o">.</span><span class="n">mouse_up</span><span class="p">)</span>

        <span class="n">row1</span> <span class="o">=</span> <span class="n">Tkinter</span><span class="o">.</span><span class="n">Frame</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">top</span><span class="p">)</span>
        <span class="n">row1</span><span class="o">.</span><span class="n">pack</span><span class="p">(</span><span class="n">side</span><span class="o">=</span><span class="s">&#39;top&#39;</span><span class="p">)</span>
        <span class="n">Tkinter</span><span class="o">.</span><span class="n">Button</span><span class="p">(</span><span class="n">row1</span><span class="p">,</span> <span class="n">text</span><span class="o">=</span><span class="s">&#39;Interpolate to grid&#39;</span><span class="p">,</span>
            <span class="n">width</span><span class="o">=</span><span class="mi">20</span><span class="p">,</span> <span class="n">command</span><span class="o">=</span><span class="bp">self</span><span class="o">.</span><span class="n">interpolate</span><span class="p">)</span><span class="o">.</span><span class="n">pack</span><span class="p">(</span><span class="n">side</span><span class="o">=</span><span class="s">&#39;left&#39;</span><span class="p">,</span><span class="n">padx</span><span class="o">=</span><span class="mi">2</span><span class="p">)</span>
        <span class="n">Tkinter</span><span class="o">.</span><span class="n">Button</span><span class="p">(</span><span class="n">row1</span><span class="p">,</span> <span class="n">text</span><span class="o">=</span><span class="s">&#39;Erase drawing&#39;</span><span class="p">,</span>
            <span class="n">width</span><span class="o">=</span><span class="mi">20</span><span class="p">,</span> <span class="n">command</span><span class="o">=</span><span class="bp">self</span><span class="o">.</span><span class="n">erase</span><span class="p">)</span><span class="o">.</span><span class="n">pack</span><span class="p">(</span><span class="n">side</span><span class="o">=</span><span class="s">&#39;left&#39;</span><span class="p">,</span><span class="n">padx</span><span class="o">=</span><span class="mi">2</span><span class="p">)</span>

        <span class="bp">self</span><span class="o">.</span><span class="n">erase</span><span class="p">()</span> <span class="c"># some init</span>
</div>
<div class="viewcode-block" id="DrawFunction.pack"><a class="viewcode-back" href="../../TkGUI.html#scitools.TkGUI.DrawFunction.pack">[docs]</a>    <span class="k">def</span> <span class="nf">pack</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="o">**</span><span class="n">kwargs</span><span class="p">):</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">top</span><span class="o">.</span><span class="n">pack</span><span class="p">(</span><span class="n">kwargs</span><span class="p">,</span> <span class="n">expand</span><span class="o">=</span><span class="mi">1</span><span class="p">,</span> <span class="n">fill</span><span class="o">=</span><span class="s">&#39;both&#39;</span><span class="p">)</span>
</div>
<div class="viewcode-block" id="DrawFunction.configure"><a class="viewcode-back" href="../../TkGUI.html#scitools.TkGUI.DrawFunction.configure">[docs]</a>    <span class="k">def</span> <span class="nf">configure</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="o">**</span><span class="n">kwargs</span><span class="p">):</span>
        <span class="sd">&quot;&quot;&quot;</span>
<span class="sd">        Legal parameters (kwargs):</span>

<span class="sd">        xcoor           grid points (on the x axsis) for interpolation</span>
<span class="sd">        width, height   size of widget</span>
<span class="sd">        curvename       name of function to be drawn</span>
<span class="sd">        xlabel, ylabel  labels on the axis</span>
<span class="sd">        curvecolor      color of the drawn curve</span>
<span class="sd">        curvewidth      line thickness of the drawn curve</span>

<span class="sd">        ymin and ymax are set in set_yaxis method.</span>
<span class="sd">        &quot;&quot;&quot;</span>
        <span class="k">for</span> <span class="n">name</span> <span class="ow">in</span> <span class="n">kwargs</span><span class="p">:</span>
            <span class="k">if</span> <span class="n">name</span> <span class="o">==</span> <span class="s">&#39;xcoor&#39;</span><span class="p">:</span>
                <span class="n">xcoor</span> <span class="o">=</span> <span class="n">kwargs</span><span class="p">[</span><span class="s">&#39;xcoor&#39;</span><span class="p">]</span>
                <span class="bp">self</span><span class="o">.</span><span class="n">xcoor</span> <span class="o">=</span> <span class="n">xcoor</span>
                <span class="bp">self</span><span class="o">.</span><span class="n">xmin</span> <span class="o">=</span> <span class="nb">min</span><span class="p">(</span><span class="n">xcoor</span><span class="p">);</span> <span class="bp">self</span><span class="o">.</span><span class="n">xmax</span> <span class="o">=</span> <span class="nb">max</span><span class="p">(</span><span class="n">xcoor</span><span class="p">)</span>
                <span class="bp">self</span><span class="o">.</span><span class="n">g</span><span class="o">.</span><span class="n">xaxis_configure</span><span class="p">(</span><span class="nb">min</span><span class="o">=</span><span class="bp">self</span><span class="o">.</span><span class="n">xmin</span><span class="p">,</span> <span class="nb">max</span><span class="o">=</span><span class="bp">self</span><span class="o">.</span><span class="n">xmax</span><span class="p">)</span>
            <span class="k">elif</span> <span class="n">name</span> <span class="o">==</span> <span class="s">&#39;width&#39;</span><span class="p">:</span>
                <span class="bp">self</span><span class="o">.</span><span class="n">g</span><span class="o">.</span><span class="n">configure</span><span class="p">(</span><span class="n">width</span><span class="o">=</span><span class="n">kwargs</span><span class="p">[</span><span class="s">&#39;width&#39;</span><span class="p">])</span>
            <span class="k">elif</span> <span class="n">name</span> <span class="o">==</span> <span class="s">&#39;height&#39;</span><span class="p">:</span>
                <span class="bp">self</span><span class="o">.</span><span class="n">g</span><span class="o">.</span><span class="n">configure</span><span class="p">(</span><span class="n">width</span><span class="o">=</span><span class="n">kwargs</span><span class="p">[</span><span class="s">&#39;height&#39;</span><span class="p">])</span>
            <span class="k">elif</span> <span class="n">name</span> <span class="o">==</span> <span class="s">&#39;curvename&#39;</span><span class="p">:</span>
                <span class="bp">self</span><span class="o">.</span><span class="n">curvename</span> <span class="o">=</span> <span class="n">kwargs</span><span class="p">[</span><span class="s">&#39;curvename&#39;</span><span class="p">]</span>
            <span class="k">elif</span> <span class="n">name</span> <span class="o">==</span> <span class="s">&#39;curvecolor&#39;</span><span class="p">:</span>
                <span class="bp">self</span><span class="o">.</span><span class="n">curvecolor</span> <span class="o">=</span> <span class="n">kwargs</span><span class="p">[</span><span class="s">&#39;curvecolor&#39;</span><span class="p">]</span>
            <span class="k">elif</span> <span class="n">name</span> <span class="o">==</span> <span class="s">&#39;curvewidth&#39;</span><span class="p">:</span>
                <span class="bp">self</span><span class="o">.</span><span class="n">curvewidth</span> <span class="o">=</span> <span class="n">kwargs</span><span class="p">[</span><span class="s">&#39;curvewidth&#39;</span><span class="p">]</span>
            <span class="k">elif</span> <span class="n">name</span> <span class="o">==</span> <span class="s">&#39;xlabel&#39;</span><span class="p">:</span>
                <span class="bp">self</span><span class="o">.</span><span class="n">g</span><span class="o">.</span><span class="n">xaxis_configure</span><span class="p">(</span><span class="n">title</span><span class="o">=</span><span class="n">kwargs</span><span class="p">[</span><span class="s">&#39;xlabel&#39;</span><span class="p">])</span>
            <span class="k">elif</span> <span class="n">name</span> <span class="o">==</span> <span class="s">&#39;ylabel&#39;</span><span class="p">:</span>
                <span class="bp">self</span><span class="o">.</span><span class="n">g</span><span class="o">.</span><span class="n">xaxis_configure</span><span class="p">(</span><span class="n">title</span><span class="o">=</span><span class="n">kwargs</span><span class="p">[</span><span class="s">&#39;ylabel&#39;</span><span class="p">])</span>

        <span class="k">if</span> <span class="bp">self</span><span class="o">.</span><span class="n">curvename</span> <span class="o">==</span> <span class="s">&#39; &#39;</span><span class="p">:</span>
            <span class="bp">self</span><span class="o">.</span><span class="n">legend</span> <span class="o">=</span> <span class="s">&#39;&#39;</span>
        <span class="k">else</span><span class="p">:</span>
            <span class="bp">self</span><span class="o">.</span><span class="n">legend</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">curvename</span>
</div>
<div class="viewcode-block" id="DrawFunction.set_yaxis"><a class="viewcode-back" href="../../TkGUI.html#scitools.TkGUI.DrawFunction.set_yaxis">[docs]</a>    <span class="k">def</span> <span class="nf">set_yaxis</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">ymin</span><span class="p">,</span> <span class="n">ymax</span><span class="p">):</span>
        <span class="k">try</span><span class="p">:</span>
            <span class="bp">self</span><span class="o">.</span><span class="n">ymax_widget</span><span class="o">.</span><span class="n">setvalue</span><span class="p">(</span><span class="n">ymax</span><span class="p">)</span>
            <span class="bp">self</span><span class="o">.</span><span class="n">ymin_widget</span><span class="o">.</span><span class="n">setvalue</span><span class="p">(</span><span class="n">ymin</span><span class="p">)</span>
        <span class="k">except</span><span class="p">:</span>
            <span class="c"># no widgets for ymin, ymax</span>
            <span class="k">pass</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">g</span><span class="o">.</span><span class="n">yaxis_configure</span><span class="p">(</span><span class="nb">min</span><span class="o">=</span><span class="n">ymin</span><span class="p">,</span> <span class="nb">max</span><span class="o">=</span><span class="n">ymax</span><span class="p">)</span>
</div>
    <span class="k">def</span> <span class="nf">__ymin</span><span class="p">(</span><span class="bp">self</span><span class="p">):</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">g</span><span class="o">.</span><span class="n">yaxis_configure</span><span class="p">(</span><span class="nb">min</span><span class="o">=</span><span class="nb">float</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">ymin_widget</span><span class="o">.</span><span class="n">get</span><span class="p">()))</span>

    <span class="k">def</span> <span class="nf">__ymax</span><span class="p">(</span><span class="bp">self</span><span class="p">):</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">g</span><span class="o">.</span><span class="n">yaxis_configure</span><span class="p">(</span><span class="nb">max</span><span class="o">=</span><span class="nb">float</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">ymax_widget</span><span class="o">.</span><span class="n">get</span><span class="p">()))</span>

<div class="viewcode-block" id="DrawFunction.erase"><a class="viewcode-back" href="../../TkGUI.html#scitools.TkGUI.DrawFunction.erase">[docs]</a>    <span class="k">def</span> <span class="nf">erase</span><span class="p">(</span><span class="bp">self</span><span class="p">):</span>
        <span class="sd">&quot;&quot;&quot;delete all curves and make new empty self.x and self.y&quot;&quot;&quot;</span>
        <span class="k">for</span> <span class="n">curvename</span> <span class="ow">in</span> <span class="bp">self</span><span class="o">.</span><span class="n">g</span><span class="o">.</span><span class="n">element_show</span><span class="p">():</span>
            <span class="bp">self</span><span class="o">.</span><span class="n">g</span><span class="o">.</span><span class="n">element_delete</span><span class="p">(</span><span class="n">curvename</span><span class="p">)</span>

        <span class="bp">self</span><span class="o">.</span><span class="n">x</span> <span class="o">=</span> <span class="n">Pmw</span><span class="o">.</span><span class="n">Blt</span><span class="o">.</span><span class="n">Vector</span><span class="p">()</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">y</span> <span class="o">=</span> <span class="n">Pmw</span><span class="o">.</span><span class="n">Blt</span><span class="o">.</span><span class="n">Vector</span><span class="p">()</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">g</span><span class="o">.</span><span class="n">configure</span><span class="p">(</span><span class="n">title</span><span class="o">=</span><span class="s">&#39;0 drawn points&#39;</span><span class="p">)</span>
</div>
<div class="viewcode-block" id="DrawFunction.mouse_drag"><a class="viewcode-back" href="../../TkGUI.html#scitools.TkGUI.DrawFunction.mouse_drag">[docs]</a>    <span class="k">def</span> <span class="nf">mouse_drag</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">event</span><span class="p">):</span>
        <span class="c"># transform screen coordinates of the mouse position,</span>
        <span class="c"># (event.x,event.y) to physical coordinates (x,y):</span>
        <span class="n">x</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">g</span><span class="o">.</span><span class="n">xaxis_invtransform</span><span class="p">(</span><span class="n">event</span><span class="o">.</span><span class="n">x</span><span class="p">)</span>
        <span class="n">y</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">g</span><span class="o">.</span><span class="n">yaxis_invtransform</span><span class="p">(</span><span class="n">event</span><span class="o">.</span><span class="n">y</span><span class="p">)</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">x</span><span class="o">.</span><span class="n">append</span><span class="p">(</span><span class="n">x</span><span class="p">);</span> <span class="bp">self</span><span class="o">.</span><span class="n">y</span><span class="o">.</span><span class="n">append</span><span class="p">(</span><span class="n">y</span><span class="p">)</span>

        <span class="c"># plot the curve as soon as we have two points, BLT vectors</span>
        <span class="c"># will automatically update the graph when they get new</span>
        <span class="c"># elements...</span>
        <span class="k">if</span> <span class="nb">len</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">x</span><span class="p">)</span> <span class="o">==</span> <span class="mi">2</span><span class="p">:</span>
            <span class="k">if</span> <span class="bp">self</span><span class="o">.</span><span class="n">g</span><span class="o">.</span><span class="n">element_exists</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">curvename</span><span class="p">):</span>
                <span class="bp">self</span><span class="o">.</span><span class="n">g</span><span class="o">.</span><span class="n">element_delete</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">curvename</span><span class="p">)</span>

            <span class="bp">self</span><span class="o">.</span><span class="n">g</span><span class="o">.</span><span class="n">line_create</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">curvename</span><span class="p">,</span>
                               <span class="n">label</span><span class="o">=</span><span class="bp">self</span><span class="o">.</span><span class="n">legend</span><span class="p">,</span>
                               <span class="n">xdata</span><span class="o">=</span><span class="bp">self</span><span class="o">.</span><span class="n">x</span><span class="p">,</span>
                               <span class="n">ydata</span><span class="o">=</span><span class="bp">self</span><span class="o">.</span><span class="n">y</span><span class="p">,</span>
                               <span class="n">color</span><span class="o">=</span><span class="bp">self</span><span class="o">.</span><span class="n">curvecolor</span><span class="p">,</span>
                               <span class="n">linewidth</span><span class="o">=</span><span class="bp">self</span><span class="o">.</span><span class="n">curvewidth</span><span class="p">,</span>
                               <span class="n">outlinewidth</span><span class="o">=</span><span class="mi">0</span><span class="p">,</span> <span class="n">fill</span><span class="o">=</span><span class="s">&#39;&#39;</span><span class="p">)</span>

        <span class="bp">self</span><span class="o">.</span><span class="n">g</span><span class="o">.</span><span class="n">configure</span><span class="p">(</span><span class="n">title</span><span class="o">=</span><span class="s">&#39;</span><span class="si">%d</span><span class="s"> points drawn&#39;</span> <span class="o">%</span> <span class="nb">len</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">x</span><span class="p">))</span>
</div>
<div class="viewcode-block" id="DrawFunction.mouse_down"><a class="viewcode-back" href="../../TkGUI.html#scitools.TkGUI.DrawFunction.mouse_down">[docs]</a>    <span class="k">def</span> <span class="nf">mouse_down</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">event</span><span class="p">):</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">g</span><span class="o">.</span><span class="n">bind</span><span class="p">(</span><span class="s">&#39;&lt;Motion&gt;&#39;</span><span class="p">,</span> <span class="bp">self</span><span class="o">.</span><span class="n">mouse_drag</span><span class="p">)</span>
</div>
<div class="viewcode-block" id="DrawFunction.mouse_up"><a class="viewcode-back" href="../../TkGUI.html#scitools.TkGUI.DrawFunction.mouse_up">[docs]</a>    <span class="k">def</span> <span class="nf">mouse_up</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">event</span><span class="p">):</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">g</span><span class="o">.</span><span class="n">unbind</span><span class="p">(</span><span class="s">&#39;&lt;Motion&gt;&#39;</span><span class="p">)</span>
</div>
<div class="viewcode-block" id="DrawFunction.interpolate"><a class="viewcode-back" href="../../TkGUI.html#scitools.TkGUI.DrawFunction.interpolate">[docs]</a>    <span class="k">def</span> <span class="nf">interpolate</span><span class="p">(</span><span class="bp">self</span><span class="p">):</span>
        <span class="c"># first build a new list with the approved (x,y) pairs:</span>
        <span class="c"># if the drawn curve is too short, stretch the end points:</span>
        <span class="k">if</span> <span class="bp">self</span><span class="o">.</span><span class="n">x</span><span class="p">[</span><span class="mi">0</span><span class="p">]</span> <span class="o">&gt;</span> <span class="bp">self</span><span class="o">.</span><span class="n">xmin</span><span class="p">:</span>   <span class="bp">self</span><span class="o">.</span><span class="n">x</span><span class="p">[</span><span class="mi">0</span><span class="p">]</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">xmin</span>
        <span class="k">if</span> <span class="bp">self</span><span class="o">.</span><span class="n">x</span><span class="p">[</span><span class="o">-</span><span class="mi">1</span><span class="p">]</span> <span class="o">&lt;</span> <span class="bp">self</span><span class="o">.</span><span class="n">xmax</span><span class="p">:</span>  <span class="bp">self</span><span class="o">.</span><span class="n">x</span><span class="p">[</span><span class="o">-</span><span class="mi">1</span><span class="p">]</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">xmax</span>

        <span class="n">x</span> <span class="o">=</span> <span class="p">[];</span>  <span class="n">y</span> <span class="o">=</span> <span class="p">[];</span> <span class="n">current_xmax</span> <span class="o">=</span> <span class="o">-</span><span class="mf">9.9E+20</span>
        <span class="k">for</span> <span class="n">i</span> <span class="ow">in</span> <span class="nb">range</span><span class="p">(</span><span class="nb">len</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">x</span><span class="p">)):</span>
            <span class="c"># skip points outside [xmin,xmax]:</span>
            <span class="k">if</span> <span class="bp">self</span><span class="o">.</span><span class="n">x</span><span class="p">[</span><span class="n">i</span><span class="p">]</span> <span class="o">&gt;=</span> <span class="bp">self</span><span class="o">.</span><span class="n">xmin</span> <span class="ow">and</span> <span class="bp">self</span><span class="o">.</span><span class="n">x</span><span class="p">[</span><span class="n">i</span><span class="p">]</span> <span class="o">&lt;=</span> <span class="bp">self</span><span class="o">.</span><span class="n">xmax</span><span class="p">:</span>
                <span class="k">if</span> <span class="bp">self</span><span class="o">.</span><span class="n">x</span><span class="p">[</span><span class="n">i</span><span class="p">]</span> <span class="o">&gt;</span> <span class="n">current_xmax</span><span class="p">:</span>
                    <span class="n">x</span><span class="o">.</span><span class="n">append</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">x</span><span class="p">[</span><span class="n">i</span><span class="p">]);</span> <span class="n">y</span><span class="o">.</span><span class="n">append</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">y</span><span class="p">[</span><span class="n">i</span><span class="p">])</span>
                    <span class="n">current_xmax</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">x</span><span class="p">[</span><span class="n">i</span><span class="p">]</span>
        <span class="c"># ensure that the end points are included:</span>
        <span class="k">if</span> <span class="n">x</span><span class="p">[</span><span class="mi">0</span><span class="p">]</span>  <span class="o">&gt;</span> <span class="bp">self</span><span class="o">.</span><span class="n">xmin</span><span class="p">:</span>
            <span class="n">x</span><span class="o">.</span><span class="n">insert</span><span class="p">(</span><span class="mi">0</span><span class="p">,</span><span class="bp">self</span><span class="o">.</span><span class="n">xmin</span><span class="p">);</span> <span class="n">y</span><span class="o">.</span><span class="n">insert</span><span class="p">(</span><span class="mi">0</span><span class="p">,</span><span class="n">y</span><span class="p">[</span><span class="mi">0</span><span class="p">])</span>
        <span class="k">if</span> <span class="n">x</span><span class="p">[</span><span class="o">-</span><span class="mi">1</span><span class="p">]</span> <span class="o">&lt;</span> <span class="bp">self</span><span class="o">.</span><span class="n">xmax</span><span class="p">:</span>
            <span class="n">x</span><span class="o">.</span><span class="n">append</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">xmax</span><span class="p">);</span> <span class="n">y</span><span class="o">.</span><span class="n">append</span><span class="p">(</span><span class="n">y</span><span class="p">[</span><span class="o">-</span><span class="mi">1</span><span class="p">])</span>

        <span class="bp">self</span><span class="o">.</span><span class="n">f</span> <span class="o">=</span> <span class="n">points2grid</span><span class="p">(</span><span class="n">x</span><span class="p">,</span> <span class="n">y</span><span class="p">,</span> <span class="bp">self</span><span class="o">.</span><span class="n">xcoor</span><span class="p">)</span>
        <span class="c"># the interpolated curve is now (self.xcoor,self.f)</span>
        <span class="c"># both are NumPy arrays</span>

        <span class="k">if</span> <span class="bp">self</span><span class="o">.</span><span class="n">g</span><span class="o">.</span><span class="n">element_exists</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">curvename</span> <span class="o">+</span> <span class="s">&#39;_i&#39;</span><span class="p">):</span>
            <span class="bp">self</span><span class="o">.</span><span class="n">g</span><span class="o">.</span><span class="n">element_delete</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">curvename</span> <span class="o">+</span> <span class="s">&#39;_i&#39;</span><span class="p">)</span>
        <span class="k">if</span> <span class="nb">len</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">xcoor</span><span class="p">)</span> <span class="o">&gt;</span> <span class="mi">30</span><span class="p">:</span>
            <span class="c"># many points, remove drawn curve, replace by interpolated data:</span>
            <span class="bp">self</span><span class="o">.</span><span class="n">g</span><span class="o">.</span><span class="n">element_delete</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">curvename</span><span class="p">)</span>
            <span class="n">circles</span> <span class="o">=</span> <span class="mi">0</span>
        <span class="k">else</span><span class="p">:</span>
            <span class="c"># keep drawn curve, add circles at interpolation points:</span>
            <span class="n">circles</span> <span class="o">=</span> <span class="mi">1</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">g</span><span class="o">.</span><span class="n">line_create</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">curvename</span> <span class="o">+</span> <span class="s">&#39;_i&#39;</span><span class="p">,</span>
                           <span class="n">label</span><span class="o">=</span><span class="bp">self</span><span class="o">.</span><span class="n">legend</span><span class="p">,</span>
                           <span class="n">xdata</span><span class="o">=</span><span class="nb">tuple</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">xcoor</span><span class="p">),</span>
                           <span class="n">ydata</span><span class="o">=</span><span class="nb">tuple</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">f</span><span class="p">),</span>
                           <span class="n">color</span><span class="o">=</span><span class="s">&#39;blue&#39;</span><span class="p">,</span>
                           <span class="n">linewidth</span><span class="o">=</span><span class="mi">1</span><span class="p">,</span>
                           <span class="n">outlinewidth</span><span class="o">=</span><span class="n">circles</span><span class="p">,</span> <span class="n">fill</span><span class="o">=</span><span class="s">&#39;&#39;</span><span class="p">)</span>
</div>
<div class="viewcode-block" id="DrawFunction.get"><a class="viewcode-back" href="../../TkGUI.html#scitools.TkGUI.DrawFunction.get">[docs]</a>    <span class="k">def</span> <span class="nf">get</span><span class="p">(</span><span class="bp">self</span><span class="p">):</span>
        <span class="sd">&quot;&quot;&quot;</span>
<span class="sd">        return points (x,y), interpolated to the grid, where</span>
<span class="sd">        x and y are NumPy arrays of coordinates</span>
<span class="sd">        &quot;&quot;&quot;</span>
        <span class="k">try</span><span class="p">:</span>
            <span class="k">return</span> <span class="bp">self</span><span class="o">.</span><span class="n">xcoor</span><span class="p">,</span> <span class="bp">self</span><span class="o">.</span><span class="n">f</span>
        <span class="k">except</span><span class="p">:</span>
            <span class="k">raise</span> <span class="ne">AttributeError</span><span class="p">(</span><span class="s">&#39;No drawing! Draw the curve first!&#39;</span><span class="p">)</span>

</div></div>
<div class="viewcode-block" id="points2grid"><a class="viewcode-back" href="../../TkGUI.html#scitools.TkGUI.points2grid">[docs]</a><span class="k">def</span> <span class="nf">points2grid</span><span class="p">(</span><span class="n">x</span><span class="p">,</span> <span class="n">y</span><span class="p">,</span> <span class="n">xcoor</span><span class="p">):</span>
    <span class="s">&quot;Transform points (x,y) to a uniform grid with coordinates xcoor.&quot;</span>
    <span class="n">L</span> <span class="o">=</span> <span class="mi">0</span><span class="p">;</span> <span class="n">R</span> <span class="o">=</span> <span class="mi">0</span>
    <span class="n">n</span> <span class="o">=</span> <span class="nb">len</span><span class="p">(</span><span class="n">xcoor</span><span class="p">)</span>
    <span class="n">m</span> <span class="o">=</span> <span class="nb">len</span><span class="p">(</span><span class="n">x</span><span class="p">)</span>
    <span class="kn">from</span> <span class="nn">numpy</span> <span class="kn">import</span> <span class="n">zeros</span>
    <span class="n">f</span> <span class="o">=</span> <span class="n">zeros</span><span class="p">(</span><span class="n">n</span><span class="p">)</span>
    <span class="k">for</span> <span class="n">i</span> <span class="ow">in</span> <span class="nb">range</span><span class="p">(</span><span class="n">n</span><span class="p">):</span>
        <span class="n">xi</span> <span class="o">=</span> <span class="n">xcoor</span><span class="p">[</span><span class="n">i</span><span class="p">]</span>
        <span class="c"># find j such that xi is between x[j-1] and x[j]</span>
        <span class="n">j</span> <span class="o">=</span> <span class="n">L</span>  <span class="c"># we know that xcoor[i-1]&gt;L so x[i]&gt;L</span>
        <span class="k">while</span> <span class="n">j</span> <span class="o">&lt;</span> <span class="n">m</span><span class="o">-</span><span class="mi">1</span> <span class="ow">and</span> <span class="n">x</span><span class="p">[</span><span class="n">j</span><span class="p">]</span> <span class="o">&lt;=</span> <span class="n">xi</span><span class="p">:</span>
            <span class="n">j</span> <span class="o">+=</span> <span class="mi">1</span>
        <span class="k">if</span> <span class="n">j</span> <span class="o">&lt;</span> <span class="n">m</span><span class="p">:</span>
            <span class="n">L</span> <span class="o">=</span> <span class="n">j</span><span class="o">-</span><span class="mi">1</span><span class="p">;</span> <span class="n">R</span> <span class="o">=</span> <span class="n">j</span>
            <span class="c">#print &quot;i=%d xi=%g; in between x[%d]=%g and x[%d]=%g&quot; % (i,xi,L,x[L],R,x[R])</span>
            <span class="c"># linear interpolation:</span>
            <span class="n">f</span><span class="p">[</span><span class="n">i</span><span class="p">]</span> <span class="o">=</span> <span class="n">y</span><span class="p">[</span><span class="n">L</span><span class="p">]</span> <span class="o">+</span> <span class="p">(</span><span class="n">y</span><span class="p">[</span><span class="n">R</span><span class="p">]</span><span class="o">-</span><span class="n">y</span><span class="p">[</span><span class="n">L</span><span class="p">])</span><span class="o">/</span><span class="p">(</span><span class="n">x</span><span class="p">[</span><span class="n">R</span><span class="p">]</span><span class="o">-</span><span class="n">x</span><span class="p">[</span><span class="n">L</span><span class="p">])</span><span class="o">*</span><span class="p">(</span><span class="n">xi</span><span class="o">-</span><span class="n">x</span><span class="p">[</span><span class="n">L</span><span class="p">])</span>
        <span class="k">else</span><span class="p">:</span>
            <span class="k">raise</span> <span class="ne">ValueError</span><span class="p">(</span><span class="s">&quot;bug&quot;</span><span class="p">)</span>
    <span class="k">return</span> <span class="n">f</span>

</div>
<div class="viewcode-block" id="DrawFunctionDialog"><a class="viewcode-back" href="../../TkGUI.html#scitools.TkGUI.DrawFunctionDialog">[docs]</a><span class="k">class</span> <span class="nc">DrawFunctionDialog</span><span class="p">:</span>
<div class="viewcode-block" id="DrawFunctionDialog.__init__"><a class="viewcode-back" href="../../TkGUI.html#scitools.TkGUI.DrawFunctionDialog.__init__">[docs]</a>    <span class="k">def</span> <span class="nf">__init__</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">xcoor</span><span class="p">,</span> <span class="n">parent</span><span class="o">=</span><span class="bp">None</span><span class="p">):</span>
        <span class="sd">&quot;&quot;&quot;Dialog box with DrawFunction widget&quot;&quot;&quot;</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">d</span> <span class="o">=</span> <span class="n">Pmw</span><span class="o">.</span><span class="n">Dialog</span><span class="p">(</span><span class="n">parent</span><span class="p">,</span>
                            <span class="n">title</span><span class="o">=</span><span class="s">&#39;Programmer-Defined Dialog&#39;</span><span class="p">,</span>
                            <span class="n">buttons</span><span class="o">=</span><span class="p">(</span><span class="s">&#39;Approved&#39;</span><span class="p">,</span> <span class="s">&#39;Cancel&#39;</span><span class="p">),</span>
                            <span class="n">command</span><span class="o">=</span><span class="bp">self</span><span class="o">.</span><span class="n">action</span><span class="p">)</span>

        <span class="bp">self</span><span class="o">.</span><span class="n">d_gui</span> <span class="o">=</span> <span class="n">DrawFunction</span><span class="p">(</span><span class="n">xcoor</span><span class="p">,</span> <span class="bp">self</span><span class="o">.</span><span class="n">d</span><span class="o">.</span><span class="n">interior</span><span class="p">())</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">d_gui</span><span class="o">.</span><span class="n">pack</span><span class="p">(</span><span class="n">padx</span><span class="o">=</span><span class="mi">10</span><span class="p">,</span><span class="n">pady</span><span class="o">=</span><span class="mi">10</span><span class="p">)</span>
</div>
<div class="viewcode-block" id="DrawFunctionDialog.action"><a class="viewcode-back" href="../../TkGUI.html#scitools.TkGUI.DrawFunctionDialog.action">[docs]</a>    <span class="k">def</span> <span class="nf">action</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">result</span><span class="p">):</span>
        <span class="k">if</span> <span class="n">result</span> <span class="o">==</span> <span class="s">&#39;Approved&#39;</span><span class="p">:</span>
            <span class="bp">self</span><span class="o">.</span><span class="n">x</span><span class="p">,</span> <span class="bp">self</span><span class="o">.</span><span class="n">f</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">d_gui</span><span class="o">.</span><span class="n">get</span><span class="p">()</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">d</span><span class="o">.</span><span class="n">destroy</span><span class="p">()</span>
</div>
<div class="viewcode-block" id="DrawFunctionDialog.get"><a class="viewcode-back" href="../../TkGUI.html#scitools.TkGUI.DrawFunctionDialog.get">[docs]</a>    <span class="k">def</span> <span class="nf">get</span><span class="p">(</span><span class="bp">self</span><span class="p">):</span>
        <span class="k">return</span> <span class="bp">self</span><span class="o">.</span><span class="n">x</span><span class="p">,</span> <span class="bp">self</span><span class="o">.</span><span class="n">f</span>

</div></div>
<span class="k">def</span> <span class="nf">_test_DrawFunction</span><span class="p">():</span>
    <span class="n">root</span> <span class="o">=</span> <span class="n">Tkinter</span><span class="o">.</span><span class="n">Tk</span><span class="p">()</span>
    <span class="n">Pmw</span><span class="o">.</span><span class="n">initialise</span><span class="p">(</span><span class="n">root</span><span class="p">)</span>
    <span class="kn">import</span> <span class="nn">scitools.misc</span><span class="p">;</span> <span class="n">scitools</span><span class="o">.</span><span class="n">misc</span><span class="o">.</span><span class="n">fontscheme6</span><span class="p">(</span><span class="n">root</span><span class="p">)</span>
    <span class="n">root</span><span class="o">.</span><span class="n">title</span><span class="p">(</span><span class="s">&#39;DrawFunction demo&#39;</span><span class="p">)</span>
    <span class="kn">from</span> <span class="nn">numpy</span> <span class="kn">import</span> <span class="n">linspace</span>
    <span class="n">x</span> <span class="o">=</span> <span class="n">linspace</span><span class="p">(</span><span class="mi">0</span><span class="p">,</span> <span class="mi">1</span><span class="p">,</span> <span class="mi">21</span><span class="p">)</span>
    <span class="n">df</span> <span class="o">=</span> <span class="n">DrawFunction</span><span class="p">(</span><span class="n">x</span><span class="p">,</span> <span class="n">root</span><span class="p">)</span>
    <span class="n">df</span><span class="o">.</span><span class="n">pack</span><span class="p">()</span>
<span class="c">#    Tkinter.Button(root, text=&#39;Print coordinates (interpolated to grid)&#39;,</span>
<span class="c">#           command=lambda o=df: sys.stdout.write(str(o.get()[1]))).pack(pady=2)</span>
    <span class="n">root</span><span class="o">.</span><span class="n">mainloop</span><span class="p">()</span>


<div class="viewcode-block" id="roundInt"><a class="viewcode-back" href="../../TkGUI.html#scitools.TkGUI.roundInt">[docs]</a><span class="k">def</span> <span class="nf">roundInt</span><span class="p">(</span><span class="n">a</span><span class="p">):</span> <span class="k">return</span> <span class="nb">int</span><span class="p">(</span><span class="n">a</span><span class="o">+</span><span class="mf">0.5</span><span class="p">)</span>
</div>
<div class="viewcode-block" id="CanvasCoords"><a class="viewcode-back" href="../../TkGUI.html#scitools.TkGUI.CanvasCoords">[docs]</a><span class="k">class</span> <span class="nc">CanvasCoords</span><span class="p">:</span>
    <span class="sd">&quot;&quot;&quot;</span>
<span class="sd">    Utilities for transforming between canvas coordinates and</span>
<span class="sd">    physical (real) coordinates.</span>
<span class="sd">    &quot;&quot;&quot;</span>
<div class="viewcode-block" id="CanvasCoords.__init__"><a class="viewcode-back" href="../../TkGUI.html#scitools.TkGUI.CanvasCoords.__init__">[docs]</a>    <span class="k">def</span> <span class="nf">__init__</span><span class="p">(</span><span class="bp">self</span><span class="p">):</span>
        <span class="c"># 400x400 pixels is default:</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">canvas_x</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">canvas_y</span> <span class="o">=</span> <span class="mi">400</span>
        <span class="c"># origin: lower left corner:</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">x_origin</span> <span class="o">=</span> <span class="mi">0</span><span class="p">;</span> <span class="bp">self</span><span class="o">.</span><span class="n">y_origin</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">canvas_y</span>
        <span class="c"># x and y measured in pixels:</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">x_range</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">canvas_x</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">xy_scale</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">canvas_x</span><span class="o">/</span><span class="bp">self</span><span class="o">.</span><span class="n">x_range</span>
</div>
<div class="viewcode-block" id="CanvasCoords.set_coordinate_system"><a class="viewcode-back" href="../../TkGUI.html#scitools.TkGUI.CanvasCoords.set_coordinate_system">[docs]</a>    <span class="k">def</span> <span class="nf">set_coordinate_system</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">canvas_width</span><span class="p">,</span> <span class="n">canvas_height</span><span class="p">,</span>
                              <span class="n">x_origin</span><span class="p">,</span> <span class="n">y_origin</span><span class="p">,</span> <span class="n">x_range</span> <span class="o">=</span> <span class="mf">1.0</span><span class="p">):</span>
        <span class="sd">&quot;&quot;&quot;</span>
<span class="sd">        Define parameters in the physical coordinate system</span>
<span class="sd">        (origin, width) expressed in canvas coordinates.</span>
<span class="sd">        x_range is the width of canvas window in physical coordinates.</span>
<span class="sd">        &quot;&quot;&quot;</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">canvas_x</span> <span class="o">=</span> <span class="n">canvas_width</span>   <span class="c"># width  of canvas window</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">canvas_y</span> <span class="o">=</span> <span class="n">canvas_height</span>  <span class="c"># height of canvas window</span>

        <span class="c"># the origin in canvas coordinates:</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">x_origin</span> <span class="o">=</span> <span class="n">x_origin</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">y_origin</span> <span class="o">=</span> <span class="n">y_origin</span>

        <span class="c"># x range (canvas_x in physical coords):</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">x_range</span> <span class="o">=</span> <span class="n">x_range</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">xy_scale</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">canvas_x</span><span class="o">/</span><span class="bp">self</span><span class="o">.</span><span class="n">x_range</span>
</div>
<div class="viewcode-block" id="CanvasCoords.print_coordinate_system"><a class="viewcode-back" href="../../TkGUI.html#scitools.TkGUI.CanvasCoords.print_coordinate_system">[docs]</a>    <span class="k">def</span> <span class="nf">print_coordinate_system</span><span class="p">(</span><span class="bp">self</span><span class="p">):</span>
        <span class="k">print</span> <span class="s">&quot;canvas = (</span><span class="si">%d</span><span class="s">,</span><span class="si">%d</span><span class="s">)&quot;</span> <span class="o">%</span> <span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">canvas_x</span><span class="p">,</span> <span class="bp">self</span><span class="o">.</span><span class="n">canvas_y</span><span class="p">)</span>
        <span class="k">print</span> <span class="s">&quot;canvas origin = (</span><span class="si">%d</span><span class="s">,</span><span class="si">%d</span><span class="s">)&quot;</span> <span class="o">%</span> <span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">x_origin</span><span class="p">,</span> <span class="bp">self</span><span class="o">.</span><span class="n">y_origin</span><span class="p">)</span>
        <span class="k">print</span> <span class="s">&quot;range of physical x coordinate =&quot;</span><span class="p">,</span> <span class="bp">self</span><span class="o">.</span><span class="n">x_range</span>
        <span class="k">print</span> <span class="s">&quot;xy_scale (from physical to canvas): &quot;</span><span class="p">,</span> <span class="bp">self</span><span class="o">.</span><span class="n">xy_scale</span>

    <span class="c"># --- transformations between physical and canvas coordinates: ---</span>
</div>
<div class="viewcode-block" id="CanvasCoords.physical2canvas"><a class="viewcode-back" href="../../TkGUI.html#scitools.TkGUI.CanvasCoords.physical2canvas">[docs]</a>    <span class="k">def</span> <span class="nf">physical2canvas</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">x</span><span class="p">,</span> <span class="n">y</span><span class="p">):</span>
        <span class="sd">&quot;&quot;&quot;Transform physical (x,y) to canvas 2-tuple.&quot;&quot;&quot;</span>
        <span class="k">return</span> <span class="p">(</span><span class="n">roundInt</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">x_origin</span> <span class="o">+</span> <span class="n">x</span><span class="o">*</span><span class="bp">self</span><span class="o">.</span><span class="n">xy_scale</span><span class="p">),</span>
                <span class="n">roundInt</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">y_origin</span> <span class="o">-</span> <span class="n">y</span><span class="o">*</span><span class="bp">self</span><span class="o">.</span><span class="n">xy_scale</span><span class="p">))</span>
</div>
<div class="viewcode-block" id="CanvasCoords.cx"><a class="viewcode-back" href="../../TkGUI.html#scitools.TkGUI.CanvasCoords.cx">[docs]</a>    <span class="k">def</span> <span class="nf">cx</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span><span class="n">x</span><span class="p">):</span>
        <span class="sd">&quot;&quot;&quot;Transform physical x to canvas x.&quot;&quot;&quot;</span>
        <span class="k">return</span> <span class="n">roundInt</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">x_origin</span> <span class="o">+</span> <span class="n">x</span><span class="o">*</span><span class="bp">self</span><span class="o">.</span><span class="n">xy_scale</span><span class="p">)</span>
</div>
<div class="viewcode-block" id="CanvasCoords.cy"><a class="viewcode-back" href="../../TkGUI.html#scitools.TkGUI.CanvasCoords.cy">[docs]</a>    <span class="k">def</span> <span class="nf">cy</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span><span class="n">y</span><span class="p">):</span>
        <span class="sd">&quot;&quot;&quot;Transform physical y to canvas y.&quot;&quot;&quot;</span>
        <span class="k">return</span> <span class="n">roundInt</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">y_origin</span> <span class="o">-</span> <span class="n">y</span><span class="o">*</span><span class="bp">self</span><span class="o">.</span><span class="n">xy_scale</span><span class="p">)</span>
</div>
<div class="viewcode-block" id="CanvasCoords.physical2canvas4"><a class="viewcode-back" href="../../TkGUI.html#scitools.TkGUI.CanvasCoords.physical2canvas4">[docs]</a>    <span class="k">def</span> <span class="nf">physical2canvas4</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">coords</span><span class="p">):</span>
        <span class="sd">&quot;&quot;&quot;</span>
<span class="sd">        Transform physical 4-tuple (x1,x2,y1,y2) to</span>
<span class="sd">        canvas 4-tuple.</span>
<span class="sd">        &quot;&quot;&quot;</span>
        <span class="k">return</span> <span class="p">(</span><span class="n">roundInt</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">x_origin</span> <span class="o">+</span> <span class="n">coords</span><span class="p">[</span><span class="mi">0</span><span class="p">]</span><span class="o">*</span><span class="bp">self</span><span class="o">.</span><span class="n">xy_scale</span><span class="p">),</span>
                <span class="n">roundInt</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">y_origin</span> <span class="o">-</span> <span class="n">coords</span><span class="p">[</span><span class="mi">1</span><span class="p">]</span><span class="o">*</span><span class="bp">self</span><span class="o">.</span><span class="n">xy_scale</span><span class="p">),</span>
                <span class="n">roundInt</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">x_origin</span> <span class="o">+</span> <span class="n">coords</span><span class="p">[</span><span class="mi">2</span><span class="p">]</span><span class="o">*</span><span class="bp">self</span><span class="o">.</span><span class="n">xy_scale</span><span class="p">),</span>
                <span class="n">roundInt</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">y_origin</span> <span class="o">-</span> <span class="n">coords</span><span class="p">[</span><span class="mi">3</span><span class="p">]</span><span class="o">*</span><span class="bp">self</span><span class="o">.</span><span class="n">xy_scale</span><span class="p">))</span>
</div>
<div class="viewcode-block" id="CanvasCoords.canvas2physical"><a class="viewcode-back" href="../../TkGUI.html#scitools.TkGUI.CanvasCoords.canvas2physical">[docs]</a>    <span class="k">def</span> <span class="nf">canvas2physical</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">x</span><span class="p">,</span> <span class="n">y</span><span class="p">):</span>
        <span class="sd">&quot;&quot;&quot;Inverse of physical2canvas.&quot;&quot;&quot;</span>
        <span class="k">return</span> <span class="p">(</span><span class="nb">float</span><span class="p">((</span><span class="n">x</span> <span class="o">-</span> <span class="bp">self</span><span class="o">.</span><span class="n">x_origin</span><span class="p">)</span><span class="o">/</span><span class="bp">self</span><span class="o">.</span><span class="n">xy_scale</span><span class="p">),</span>
                <span class="nb">float</span><span class="p">((</span><span class="bp">self</span><span class="o">.</span><span class="n">y_origin</span> <span class="o">-</span> <span class="n">y</span><span class="p">)</span><span class="o">/</span><span class="bp">self</span><span class="o">.</span><span class="n">xy_scale</span><span class="p">))</span>
</div>
<div class="viewcode-block" id="CanvasCoords.canvas2physical4"><a class="viewcode-back" href="../../TkGUI.html#scitools.TkGUI.CanvasCoords.canvas2physical4">[docs]</a>    <span class="k">def</span> <span class="nf">canvas2physical4</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">coords</span><span class="p">):</span>
        <span class="sd">&quot;&quot;&quot;Inverse of physical2canvas4.&quot;&quot;&quot;</span>
        <span class="k">return</span> <span class="p">(</span><span class="nb">float</span><span class="p">((</span><span class="n">coords</span><span class="p">[</span><span class="mi">0</span><span class="p">]</span> <span class="o">-</span> <span class="bp">self</span><span class="o">.</span><span class="n">x_origin</span><span class="p">)</span><span class="o">/</span><span class="bp">self</span><span class="o">.</span><span class="n">xy_scale</span><span class="p">),</span>
                <span class="nb">float</span><span class="p">((</span><span class="bp">self</span><span class="o">.</span><span class="n">y_origin</span> <span class="o">-</span> <span class="n">coords</span><span class="p">[</span><span class="mi">1</span><span class="p">])</span><span class="o">/</span><span class="bp">self</span><span class="o">.</span><span class="n">xy_scale</span><span class="p">),</span>
                <span class="nb">float</span><span class="p">((</span><span class="n">coords</span><span class="p">[</span><span class="mi">2</span><span class="p">]</span> <span class="o">-</span> <span class="bp">self</span><span class="o">.</span><span class="n">x_origin</span><span class="p">)</span><span class="o">/</span><span class="bp">self</span><span class="o">.</span><span class="n">xy_scale</span><span class="p">),</span>
                <span class="nb">float</span><span class="p">((</span><span class="bp">self</span><span class="o">.</span><span class="n">y_origin</span> <span class="o">-</span> <span class="n">coords</span><span class="p">[</span><span class="mi">3</span><span class="p">])</span><span class="o">/</span><span class="bp">self</span><span class="o">.</span><span class="n">xy_scale</span><span class="p">))</span>
</div>
<div class="viewcode-block" id="CanvasCoords.scale"><a class="viewcode-back" href="../../TkGUI.html#scitools.TkGUI.CanvasCoords.scale">[docs]</a>    <span class="k">def</span> <span class="nf">scale</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">dx</span><span class="p">):</span>
        <span class="sd">&quot;&quot;&quot;</span>
<span class="sd">        Transform a length in canvas coordinates</span>
<span class="sd">        to a length in physical coordinates.</span>
<span class="sd">        &quot;&quot;&quot;</span>
        <span class="k">return</span> <span class="bp">self</span><span class="o">.</span><span class="n">xy_scale</span><span class="o">*</span><span class="n">dx</span>

    <span class="c"># short forms:</span></div>
    <span class="n">c2p</span>  <span class="o">=</span> <span class="n">canvas2physical</span>
    <span class="n">c2p4</span> <span class="o">=</span> <span class="n">canvas2physical4</span>
    <span class="n">p2c</span>  <span class="o">=</span> <span class="n">physical2canvas</span>
    <span class="n">p2c4</span> <span class="o">=</span> <span class="n">physical2canvas4</span>
</div>
<span class="k">def</span> <span class="nf">_CanvasCoords_test</span><span class="p">():</span>
    <span class="n">root</span> <span class="o">=</span> <span class="n">Tkinter</span><span class="o">.</span><span class="n">Tk</span><span class="p">()</span>
    <span class="n">c</span> <span class="o">=</span> <span class="n">Tkinter</span><span class="o">.</span><span class="n">Canvas</span><span class="p">(</span><span class="n">root</span><span class="p">,</span><span class="n">width</span><span class="o">=</span><span class="mi">400</span><span class="p">,</span> <span class="n">height</span><span class="o">=</span><span class="mi">400</span><span class="p">)</span>
    <span class="n">c</span><span class="o">.</span><span class="n">pack</span><span class="p">()</span>
    <span class="c"># let physical (x,y) be at (200,200) and let the x range be 2:</span>
    <span class="n">C</span><span class="o">.</span><span class="n">set_coordinate_system</span><span class="p">(</span><span class="mi">400</span><span class="p">,</span><span class="mi">400</span><span class="p">,</span> <span class="mi">200</span><span class="p">,</span><span class="mi">200</span><span class="p">,</span> <span class="mf">2.0</span><span class="p">)</span>
    <span class="n">cc</span> <span class="o">=</span> <span class="n">C</span><span class="o">.</span><span class="n">p2c4</span><span class="p">((</span><span class="mf">0.2</span><span class="p">,</span> <span class="mf">0.2</span><span class="p">,</span> <span class="mf">0.6</span><span class="p">,</span> <span class="mf">0.6</span><span class="p">))</span>
    <span class="n">c</span><span class="o">.</span><span class="n">create_oval</span><span class="p">(</span><span class="n">cc</span><span class="p">[</span><span class="mi">0</span><span class="p">],</span><span class="n">cc</span><span class="p">[</span><span class="mi">1</span><span class="p">],</span><span class="n">cc</span><span class="p">[</span><span class="mi">2</span><span class="p">],</span><span class="n">cc</span><span class="p">[</span><span class="mi">3</span><span class="p">],</span><span class="n">fill</span><span class="o">=</span><span class="s">&#39;red&#39;</span><span class="p">,</span><span class="n">outline</span><span class="o">=</span><span class="s">&#39;blue&#39;</span><span class="p">)</span>
    <span class="n">c1</span><span class="p">,</span> <span class="n">c2</span> <span class="o">=</span> <span class="n">C</span><span class="o">.</span><span class="n">physical2canvas</span><span class="p">(</span><span class="mf">0.2</span><span class="p">,</span><span class="mf">0.2</span><span class="p">)</span>
    <span class="n">c</span><span class="o">.</span><span class="n">create_text</span><span class="p">(</span><span class="n">c1</span><span class="p">,</span> <span class="n">c2</span><span class="p">,</span> <span class="n">text</span><span class="o">=</span><span class="s">&#39;(0.2,0.2)&#39;</span><span class="p">)</span>
    <span class="n">c1</span><span class="p">,</span> <span class="n">c2</span> <span class="o">=</span> <span class="n">C</span><span class="o">.</span><span class="n">physical2canvas</span><span class="p">(</span><span class="mf">0.6</span><span class="p">,</span><span class="mf">0.6</span><span class="p">)</span>
    <span class="n">c</span><span class="o">.</span><span class="n">create_text</span><span class="p">(</span><span class="n">c1</span><span class="p">,</span> <span class="n">c2</span><span class="p">,</span> <span class="n">text</span><span class="o">=</span><span class="s">&#39;(0.6,0.6)&#39;</span><span class="p">)</span>
    <span class="n">c</span><span class="o">.</span><span class="n">create_line</span><span class="p">(</span><span class="n">C</span><span class="o">.</span><span class="n">cx</span><span class="p">(</span><span class="mf">0.2</span><span class="p">),</span> <span class="n">C</span><span class="o">.</span><span class="n">cy</span><span class="p">(</span><span class="mf">0.2</span><span class="p">),</span>
                  <span class="n">C</span><span class="o">.</span><span class="n">cx</span><span class="p">(</span><span class="mf">0.6</span><span class="p">),</span> <span class="n">C</span><span class="o">.</span><span class="n">cy</span><span class="p">(</span><span class="mf">0.2</span><span class="p">),</span>
                  <span class="n">C</span><span class="o">.</span><span class="n">cx</span><span class="p">(</span><span class="mf">0.6</span><span class="p">),</span> <span class="n">C</span><span class="o">.</span><span class="n">cy</span><span class="p">(</span><span class="mf">0.6</span><span class="p">),</span>
                  <span class="n">C</span><span class="o">.</span><span class="n">cx</span><span class="p">(</span><span class="mf">0.2</span><span class="p">),</span> <span class="n">C</span><span class="o">.</span><span class="n">cy</span><span class="p">(</span><span class="mf">0.6</span><span class="p">),</span>
                  <span class="n">C</span><span class="o">.</span><span class="n">cx</span><span class="p">(</span><span class="mf">0.2</span><span class="p">),</span> <span class="n">C</span><span class="o">.</span><span class="n">cy</span><span class="p">(</span><span class="mf">0.2</span><span class="p">))</span>



<span class="sd">&quot;&quot;&quot;</span>
<span class="sd">Utilities for holding and displaying data about input parameters.</span>
<span class="sd">&quot;&quot;&quot;</span>
<span class="kn">import</span> <span class="nn">re</span>
<span class="kn">import</span> <span class="nn">scitools.modulecheck</span>
<span class="kn">import</span> <span class="nn">scitools.misc</span>
<span class="k">try</span><span class="p">:</span>
    <span class="n">PQ</span> <span class="o">=</span> <span class="n">import_module</span><span class="p">(</span><span class="s">&#39;Scientific.Physics.PhysicalQuantities&#39;</span><span class="p">)</span>
<span class="k">except</span> <span class="ne">ImportError</span><span class="p">:</span>
    <span class="k">pass</span>

<span class="kn">from</span> <span class="nn">scitools.misc</span> <span class="kn">import</span> <span class="n">str2bool</span><span class="p">,</span> <span class="n">str2obj</span>

<div class="viewcode-block" id="InputPrm"><a class="viewcode-back" href="../../TkGUI.html#scitools.TkGUI.InputPrm">[docs]</a><span class="k">class</span> <span class="nc">InputPrm</span><span class="p">:</span>
    <span class="sd">&quot;&quot;&quot;Class for holding data about a parameter.&quot;&quot;&quot;</span>
<div class="viewcode-block" id="InputPrm.__init__"><a class="viewcode-back" href="../../TkGUI.html#scitools.TkGUI.InputPrm.__init__">[docs]</a>    <span class="k">def</span> <span class="nf">__init__</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">name</span><span class="o">=</span><span class="bp">None</span><span class="p">,</span> <span class="n">default</span><span class="o">=</span><span class="mf">0.0</span><span class="p">,</span> <span class="n">str2type</span><span class="o">=</span><span class="bp">None</span><span class="p">,</span>
                 <span class="n">help</span><span class="o">=</span><span class="bp">None</span><span class="p">,</span> <span class="n">unit</span><span class="o">=</span><span class="bp">None</span><span class="p">,</span> <span class="n">cmlarg</span><span class="o">=</span><span class="bp">None</span><span class="p">,</span> <span class="n">prmclass</span><span class="o">=</span><span class="bp">None</span><span class="p">):</span>
        <span class="sd">&quot;&quot;&quot;</span>
<span class="sd">        default           default value</span>
<span class="sd">        str2type          string to type conversion</span>
<span class="sd">                          (float, int, str, str2bool)</span>
<span class="sd">        name              parameter name</span>
<span class="sd">        help              description of parameter</span>
<span class="sd">        unit              physical unit (dimension)</span>
<span class="sd">        cmlarg            command-line argument for sending</span>
<span class="sd">                          this prm to an external program</span>
<span class="sd">        prmclass          classification of this parameter, e.g.,</span>
<span class="sd">                          &#39;numerics&#39;, &#39;physics&#39;, &#39;material&#39;, etc.</span>

<span class="sd">        Note: value with unit only works if str is float or int</span>

<span class="sd">        &gt;&gt;&gt; p=InputPrm(&#39;q&#39;, 1, float, unit=&#39;m&#39;)</span>
<span class="sd">        &gt;&gt;&gt; p.set(6)</span>
<span class="sd">        &gt;&gt;&gt; p.get()</span>
<span class="sd">        6.0</span>
<span class="sd">        &gt;&gt;&gt; p.set(&#39;6 cm&#39;)</span>
<span class="sd">        &gt;&gt;&gt; p.get()</span>
<span class="sd">        0.059999999999999998</span>
<span class="sd">        &gt;&gt;&gt; p=InputPrm(&#39;q&#39;, &#39;1 m&#39;, float, unit=&#39;m&#39;)</span>
<span class="sd">        &gt;&gt;&gt; p.set(&#39;1 km&#39;)</span>
<span class="sd">        &gt;&gt;&gt; p.get()</span>
<span class="sd">        1000.0</span>
<span class="sd">        &gt;&gt;&gt; p.get_wunit()</span>
<span class="sd">        &#39;1000.0 m&#39;</span>
<span class="sd">        &gt;&gt;&gt; p.unit</span>
<span class="sd">        &#39;m&#39;</span>
<span class="sd">        &quot;&quot;&quot;</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">str2type</span> <span class="o">=</span> <span class="n">str2type</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">name</span> <span class="o">=</span> <span class="n">name</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">help</span> <span class="o">=</span> <span class="n">help</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">unit</span> <span class="o">=</span> <span class="n">unit</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">cmlarg</span> <span class="o">=</span> <span class="n">cmlarg</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">prmclass</span> <span class="o">=</span> <span class="n">prmclass</span>
        <span class="k">if</span> <span class="n">str2type</span> <span class="ow">is</span> <span class="bp">None</span><span class="p">:</span>
            <span class="bp">self</span><span class="o">.</span><span class="n">str2type</span> <span class="o">=</span> <span class="n">scitools</span><span class="o">.</span><span class="n">misc</span><span class="o">.</span><span class="n">str2obj</span>

        <span class="c"># check that unit is a valid physical dimension:</span>
        <span class="k">if</span> <span class="bp">self</span><span class="o">.</span><span class="n">unit</span> <span class="ow">is</span> <span class="ow">not</span> <span class="bp">None</span><span class="p">:</span>
            <span class="k">try</span><span class="p">:</span>
                <span class="n">q</span> <span class="o">=</span> <span class="n">PQ</span><span class="o">.</span><span class="n">PhysicalQuantity</span><span class="p">(</span><span class="s">&#39;1.0 &#39;</span> <span class="o">+</span> <span class="nb">str</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">unit</span><span class="p">))</span>
            <span class="k">except</span><span class="p">:</span>
                <span class="k">raise</span> <span class="ne">ValueError</span><span class="p">(</span>
                    <span class="s">&#39;unit=</span><span class="si">%s</span><span class="s"> is an illegal physical unit&#39;</span> <span class="o">%</span> <span class="nb">str</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">unit</span><span class="p">))</span>
            <span class="k">if</span> <span class="bp">self</span><span class="o">.</span><span class="n">str2type</span> <span class="ow">is</span> <span class="nb">float</span> <span class="ow">or</span> <span class="bp">self</span><span class="o">.</span><span class="n">str2type</span> <span class="ow">is</span> <span class="nb">int</span><span class="p">:</span>
                <span class="k">pass</span>  <span class="c"># must have float or int when units are present</span>
            <span class="k">else</span><span class="p">:</span>
                <span class="k">raise</span> <span class="ne">ValueError</span><span class="p">(</span>
                    <span class="s">&#39;str2type must be float or int, not </span><span class="si">%s</span><span class="s">&#39;</span> <span class="o">%</span> \
                    <span class="nb">str</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">str2type</span><span class="p">))</span>

        <span class="bp">self</span><span class="o">.</span><span class="n">set</span><span class="p">(</span><span class="n">default</span><span class="p">)</span>  <span class="c"># set parameter value</span>
        <span class="n">scitools</span><span class="o">.</span><span class="n">modulecheck</span><span class="o">.</span><span class="n">exception</span><span class="p">(</span><span class="s">&#39;InputPrm constructor&#39;</span><span class="p">,</span> <span class="s">&#39;Scientific&#39;</span><span class="p">)</span>
</div>
<div class="viewcode-block" id="InputPrm.get"><a class="viewcode-back" href="../../TkGUI.html#scitools.TkGUI.InputPrm.get">[docs]</a>    <span class="k">def</span> <span class="nf">get</span><span class="p">(</span><span class="bp">self</span><span class="p">):</span>
        <span class="sd">&quot;&quot;&quot;Return the value of the parameter.&quot;&quot;&quot;</span>
        <span class="k">return</span> <span class="bp">self</span><span class="o">.</span><span class="n">_v</span>
</div>
<div class="viewcode-block" id="InputPrm.set"><a class="viewcode-back" href="../../TkGUI.html#scitools.TkGUI.InputPrm.set">[docs]</a>    <span class="k">def</span> <span class="nf">set</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">value</span><span class="p">):</span>
        <span class="sd">&quot;&quot;&quot;Set the value of the parameter.&quot;&quot;&quot;</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">_v</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">str2type</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">_scan</span><span class="p">(</span><span class="n">value</span><span class="p">))</span>
</div>
    <span class="n">v</span> <span class="o">=</span> <span class="nb">property</span><span class="p">(</span><span class="n">fget</span><span class="o">=</span><span class="n">get</span><span class="p">,</span> <span class="n">fset</span><span class="o">=</span><span class="nb">set</span><span class="p">,</span> <span class="n">doc</span><span class="o">=</span><span class="s">&#39;value of parameter&#39;</span><span class="p">)</span>

<div class="viewcode-block" id="InputPrm.get_wunit"><a class="viewcode-back" href="../../TkGUI.html#scitools.TkGUI.InputPrm.get_wunit">[docs]</a>    <span class="k">def</span> <span class="nf">get_wunit</span><span class="p">(</span><span class="bp">self</span><span class="p">):</span>
        <span class="sd">&quot;&quot;&quot;</span>
<span class="sd">        Return value with unit (dimension) as string, if it has.</span>
<span class="sd">        Otherwise, return value (with the right type).</span>
<span class="sd">        &quot;&quot;&quot;</span>
        <span class="k">if</span> <span class="bp">self</span><span class="o">.</span><span class="n">unit</span> <span class="ow">is</span> <span class="ow">not</span> <span class="bp">None</span><span class="p">:</span>
            <span class="k">return</span> <span class="nb">str</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">get</span><span class="p">())</span> <span class="o">+</span> <span class="s">&#39; &#39;</span> <span class="o">+</span> <span class="bp">self</span><span class="o">.</span><span class="n">unit</span>
        <span class="k">else</span><span class="p">:</span>
            <span class="k">return</span> <span class="bp">self</span><span class="o">.</span><span class="n">get</span><span class="p">()</span>
</div>
<div class="viewcode-block" id="InputPrm.__repr__"><a class="viewcode-back" href="../../TkGUI.html#scitools.TkGUI.InputPrm.__repr__">[docs]</a>    <span class="k">def</span> <span class="nf">__repr__</span><span class="p">(</span><span class="bp">self</span><span class="p">):</span>
        <span class="sd">&quot;&quot;&quot;Application of eval to this output creates the instance.&quot;&quot;&quot;</span>
        <span class="k">return</span> <span class="s">&quot;InputPrm(name=&#39;</span><span class="si">%s</span><span class="s">&#39;, default=</span><span class="si">%s</span><span class="s">, str2type=</span><span class="si">%s</span><span class="s">, &quot;</span>\
               <span class="s">&quot;help=</span><span class="si">%s</span><span class="s">, unit=</span><span class="si">%s</span><span class="s">, cmlarg=</span><span class="si">%s</span><span class="s">)&quot;</span> <span class="o">%</span> \
               <span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">name</span><span class="p">,</span> <span class="bp">self</span><span class="o">.</span><span class="n">__str__</span><span class="p">(),</span> <span class="bp">self</span><span class="o">.</span><span class="n">str2type</span><span class="o">.</span><span class="n">__name__</span><span class="p">,</span>
                <span class="bp">self</span><span class="o">.</span><span class="n">help</span><span class="p">,</span> <span class="bp">self</span><span class="o">.</span><span class="n">unit</span><span class="p">,</span> <span class="bp">self</span><span class="o">.</span><span class="n">cmlarg</span><span class="p">)</span>
</div>
<div class="viewcode-block" id="InputPrm.__str__"><a class="viewcode-back" href="../../TkGUI.html#scitools.TkGUI.InputPrm.__str__">[docs]</a>    <span class="k">def</span> <span class="nf">__str__</span><span class="p">(</span><span class="bp">self</span><span class="p">):</span>
        <span class="sd">&quot;&quot;&quot;</span>
<span class="sd">        Compact output; just the value as a formatted string.</span>
<span class="sd">        Note that __str__ is used by __repr__ so strings must</span>
<span class="sd">        be enclosed in quotes.</span>
<span class="sd">        &quot;&quot;&quot;</span>
        <span class="k">return</span> <span class="nb">repr</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">_v</span><span class="p">)</span> <span class="c"># ensure quotes in strings</span>
</div>
    <span class="k">def</span> <span class="nf">_handle_unit</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">v</span><span class="p">):</span>
        <span class="sd">&quot;&quot;&quot;</span>
<span class="sd">        Check if v is of the form &#39;value unit&#39;, extract value, after</span>
<span class="sd">        conversion to correct unit (if necessary).</span>
<span class="sd">        &quot;&quot;&quot;</span>
        <span class="k">if</span> <span class="nb">isinstance</span><span class="p">(</span><span class="n">v</span><span class="p">,</span> <span class="n">PQ</span><span class="o">.</span><span class="n">PhysicalQuantity</span><span class="p">):</span>
            <span class="n">v</span> <span class="o">=</span> <span class="nb">str</span><span class="p">(</span><span class="n">v</span><span class="p">)</span>  <span class="c"># convert to &#39;value unit&#39; string</span>
        <span class="k">if</span> <span class="nb">isinstance</span><span class="p">(</span><span class="n">v</span><span class="p">,</span> <span class="nb">str</span><span class="p">)</span> <span class="ow">and</span> <span class="nb">isinstance</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">unit</span><span class="p">,</span> <span class="nb">str</span><span class="p">)</span> <span class="ow">and</span> \
           <span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">str2type</span> <span class="ow">is</span> <span class="nb">float</span> <span class="ow">or</span> <span class="bp">self</span><span class="o">.</span><span class="n">str2type</span> <span class="ow">is</span> <span class="nb">int</span><span class="p">):</span>
            <span class="k">if</span> <span class="s">&#39; &#39;</span> <span class="ow">in</span> <span class="n">v</span><span class="p">:</span> <span class="c"># &#39;value unit&#39; string?</span>
                <span class="k">try</span><span class="p">:</span>
                    <span class="bp">self</span><span class="o">.</span><span class="n">pq</span> <span class="o">=</span> <span class="n">PQ</span><span class="o">.</span><span class="n">PhysicalQuantity</span><span class="p">(</span><span class="n">v</span><span class="p">)</span>
                <span class="k">except</span><span class="p">:</span>
                    <span class="k">raise</span> <span class="ne">ValueError</span><span class="p">(</span><span class="s">&#39;</span><span class="si">%s</span><span class="s"> should be </span><span class="si">%s</span><span class="s">; illegal syntax&#39;</span> <span class="o">%</span> \
                                     <span class="p">(</span><span class="n">v</span><span class="p">,</span> <span class="bp">self</span><span class="o">.</span><span class="n">str2type</span><span class="o">.</span><span class="n">__name__</span><span class="p">))</span>
                <span class="k">if</span> <span class="ow">not</span> <span class="bp">self</span><span class="o">.</span><span class="n">pq</span><span class="o">.</span><span class="n">isCompatible</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">unit</span><span class="p">):</span>
                    <span class="k">raise</span> <span class="ne">ValueError</span><span class="p">(</span>
                        <span class="s">&#39;illegal unit (</span><span class="si">%s</span><span class="s">); </span><span class="si">%s</span><span class="s"> is registered with unit </span><span class="si">%s</span><span class="s">&#39;</span> <span class="o">%</span> \
                        <span class="p">(</span><span class="n">v</span><span class="p">,</span> <span class="bp">self</span><span class="o">.</span><span class="n">name</span><span class="p">,</span> <span class="bp">self</span><span class="o">.</span><span class="n">unit</span><span class="p">))</span>
                <span class="bp">self</span><span class="o">.</span><span class="n">pq</span><span class="o">.</span><span class="n">convertToUnit</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">unit</span><span class="p">)</span>
                <span class="n">v</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">str2type</span><span class="p">(</span><span class="nb">str</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">pq</span><span class="p">)</span><span class="o">.</span><span class="n">split</span><span class="p">()[</span><span class="mi">0</span><span class="p">])</span>
                <span class="k">return</span> <span class="n">v</span>
            <span class="k">else</span><span class="p">:</span>
                <span class="c"># string value without unit given:</span>
                <span class="k">return</span> <span class="bp">self</span><span class="o">.</span><span class="n">str2type</span><span class="p">(</span><span class="n">v</span><span class="p">)</span>
        <span class="k">else</span><span class="p">:</span>  <span class="c"># no unit handling</span>
            <span class="k">if</span> <span class="nb">isinstance</span><span class="p">(</span><span class="n">v</span><span class="p">,</span> <span class="nb">str</span><span class="p">):</span>
                <span class="c"># check if a unit was given:</span>
                <span class="k">try</span><span class="p">:</span>
                    <span class="n">PQ</span><span class="o">.</span><span class="n">PhysicalQuantity</span><span class="p">(</span><span class="n">v</span><span class="p">)</span>
                    <span class="k">raise</span> <span class="ne">ValueError</span><span class="p">(</span>
                        <span class="s">&#39;parameter </span><span class="si">%s</span><span class="s"> given with dimension: </span><span class="si">%s</span><span class="s">, but &#39;</span>\
                        <span class="s">&#39;dimension is not registered&#39;</span> <span class="o">%</span> <span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">name</span><span class="p">,</span><span class="n">v</span><span class="p">))</span>
                <span class="k">except</span><span class="p">:</span>
                    <span class="k">pass</span>
            <span class="k">return</span> <span class="bp">self</span><span class="o">.</span><span class="n">str2type</span><span class="p">(</span><span class="n">v</span><span class="p">)</span>

<div class="viewcode-block" id="InputPrm.getPhysicalQuantity"><a class="viewcode-back" href="../../TkGUI.html#scitools.TkGUI.InputPrm.getPhysicalQuantity">[docs]</a>    <span class="k">def</span> <span class="nf">getPhysicalQuantity</span><span class="p">(</span><span class="bp">self</span><span class="p">):</span>
        <span class="k">if</span> <span class="bp">self</span><span class="o">.</span><span class="n">unit</span> <span class="ow">is</span> <span class="ow">not</span> <span class="bp">None</span><span class="p">:</span>
            <span class="k">try</span><span class="p">:</span>
                <span class="k">return</span> <span class="bp">self</span><span class="o">.</span><span class="n">pq</span>  <span class="c"># may be computed in _handle_unit</span>
            <span class="k">except</span><span class="p">:</span>
                <span class="k">return</span> <span class="n">PQ</span><span class="o">.</span><span class="n">PhysicalQuantity</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">get_wunit</span><span class="p">())</span>
        <span class="k">else</span><span class="p">:</span>
            <span class="k">raise</span> <span class="ne">AttributeError</span><span class="p">(</span><span class="s">&#39;parameter </span><span class="si">%s</span><span class="s"> has no registered unit&#39;</span> <span class="o">%</span> \
                                 <span class="bp">self</span><span class="o">.</span><span class="n">name</span><span class="p">)</span>
</div>
    <span class="k">def</span> <span class="nf">_scan</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">s</span><span class="p">):</span>
        <span class="sd">&quot;&quot;&quot;Interpret string s. Return number (for self._v).&quot;&quot;&quot;</span>
        <span class="c"># multiple loops?</span>
        <span class="n">v</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">_handle_unit</span><span class="p">(</span><span class="n">s</span><span class="p">)</span>
        <span class="k">return</span> <span class="bp">self</span><span class="o">.</span><span class="n">str2type</span><span class="p">(</span><span class="n">v</span><span class="p">)</span>

</div>
<div class="viewcode-block" id="commandline2dict"><a class="viewcode-back" href="../../TkGUI.html#scitools.TkGUI.commandline2dict">[docs]</a><span class="k">def</span> <span class="nf">commandline2dict</span><span class="p">(</span><span class="n">argv</span><span class="p">,</span> <span class="n">parameters</span><span class="p">):</span>
    <span class="sd">&quot;&quot;&quot;</span>
<span class="sd">    Load data from the command line into a dictionary of</span>
<span class="sd">    parameter values. The argv argument is typically sys.argv[1:].</span>
<span class="sd">    Each option --opt in argv is extracted and the</span>
<span class="sd">    proceeding value v is assigned to parameters:</span>
<span class="sd">       parameters[opt].set(v)</span>
<span class="sd">    Hence, parameters must hold objects that have a set</span>
<span class="sd">    function. Normally, parameters is a dictionary of</span>
<span class="sd">    InputPrm objects.</span>
<span class="sd">    &quot;&quot;&quot;</span>
    <span class="n">p</span> <span class="o">=</span> <span class="n">scitools</span><span class="o">.</span><span class="n">misc</span><span class="o">.</span><span class="n">cmldict</span><span class="p">(</span><span class="n">sys</span><span class="o">.</span><span class="n">argv</span><span class="p">[</span><span class="mi">1</span><span class="p">:],</span> <span class="n">cmlargs</span><span class="o">=</span><span class="bp">None</span><span class="p">,</span> <span class="n">validity</span><span class="o">=</span><span class="mi">0</span><span class="p">)</span>
    <span class="c"># p[key] holds all command-line args, we are only interested</span>
    <span class="c"># in those keys corresponding to parameters.keys()</span>
    <span class="k">for</span> <span class="n">key</span> <span class="ow">in</span> <span class="n">p</span><span class="o">.</span><span class="n">keys</span><span class="p">():</span>
        <span class="k">if</span> <span class="n">key</span> <span class="ow">in</span> <span class="n">parameters</span><span class="o">.</span><span class="n">keys</span><span class="p">():</span>
            <span class="n">parameters</span><span class="p">[</span><span class="n">key</span><span class="p">]</span><span class="o">.</span><span class="n">set</span><span class="p">(</span><span class="n">p</span><span class="p">[</span><span class="n">key</span><span class="p">])</span>


</div>
<div class="viewcode-block" id="InputPrmGUI"><a class="viewcode-back" href="../../TkGUI.html#scitools.TkGUI.InputPrmGUI">[docs]</a><span class="k">class</span> <span class="nc">InputPrmGUI</span><span class="p">(</span><span class="n">InputPrm</span><span class="p">):</span>
    <span class="sd">&quot;&quot;&quot;Represent an input parameter by a widget.&quot;&quot;&quot;</span>

    <span class="n">GUI_toolkit</span> <span class="o">=</span> <span class="s">&#39;Tkinter/Pmw&#39;</span>

<div class="viewcode-block" id="InputPrmGUI.__init__"><a class="viewcode-back" href="../../TkGUI.html#scitools.TkGUI.InputPrmGUI.__init__">[docs]</a>    <span class="k">def</span> <span class="nf">__init__</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">name</span><span class="o">=</span><span class="bp">None</span><span class="p">,</span> <span class="n">default</span><span class="o">=</span><span class="mf">0.0</span><span class="p">,</span> <span class="n">str2type</span><span class="o">=</span><span class="bp">None</span><span class="p">,</span>
                 <span class="n">widget_type</span><span class="o">=</span><span class="s">&#39;entry&#39;</span><span class="p">,</span> <span class="n">values</span><span class="o">=</span><span class="bp">None</span><span class="p">,</span> <span class="n">parent</span><span class="o">=</span><span class="bp">None</span><span class="p">,</span>
                 <span class="n">help</span><span class="o">=</span><span class="bp">None</span><span class="p">,</span> <span class="n">unit</span><span class="o">=</span><span class="bp">None</span><span class="p">,</span> <span class="n">cmlarg</span><span class="o">=</span><span class="bp">None</span><span class="p">):</span>
        <span class="sd">&quot;&quot;&quot;</span>
<span class="sd">        @param default:           default value</span>
<span class="sd">        @param str2type:          function from string to type</span>
<span class="sd">        @param name:              name of parameter</span>
<span class="sd">        @param widget_type:       entry, slider, option, checkbutton</span>
<span class="sd">        @param values:            (min,max) interval or options</span>
<span class="sd">        @param parent:            parent widget</span>
<span class="sd">        @param help:              description of parameter</span>
<span class="sd">        @param unit:              physical unit (dimension)</span>
<span class="sd">        @param cmlarg:            command-line argument for sending</span>
<span class="sd">                                  this prm to an external program</span>
<span class="sd">        &quot;&quot;&quot;</span>
        <span class="k">if</span> <span class="n">str2type</span> <span class="ow">is</span> <span class="bp">None</span><span class="p">:</span>
            <span class="n">str2type</span> <span class="o">=</span> <span class="n">scitools</span><span class="o">.</span><span class="n">misc</span><span class="o">.</span><span class="n">str2obj</span>

        <span class="c"># bind self._v to an object with get and set methods</span>
        <span class="c"># for assigning and extracting the parameter value</span>
        <span class="c"># in the associated widget:</span>
        <span class="k">if</span> <span class="n">InputPrmGUI</span><span class="o">.</span><span class="n">GUI_toolkit</span><span class="o">.</span><span class="n">startswith</span><span class="p">(</span><span class="s">&#39;Tk&#39;</span><span class="p">):</span>
            <span class="c"># use Tkinter variables</span>
            <span class="bp">self</span><span class="o">.</span><span class="n">make_GUI_variable_Tk</span><span class="p">(</span><span class="n">str2type</span><span class="p">,</span> <span class="n">unit</span><span class="p">,</span> <span class="n">name</span><span class="p">)</span>
        <span class="k">else</span><span class="p">:</span>
            <span class="k">raise</span> <span class="ne">ValueError</span><span class="p">(</span>
                <span class="s">&#39;The desired GUI toolkit </span><span class="si">%s</span><span class="s"> is not supported&#39;</span> <span class="o">%</span> \
                <span class="n">InputPrmGUI</span><span class="o">.</span><span class="n">GUI_toolkit</span><span class="p">)</span>
        <span class="c"># How to implement support for other toolkits:</span>
        <span class="c"># self._v must point to an object with a get and set method</span>
        <span class="c"># for extracting and setting the value of the parameter in</span>
        <span class="c"># the associated widget. In Tkinter self._v is a Tkinter</span>
        <span class="c"># variable (DoubleVar, StringVar, IntVar). In another toolkit</span>
        <span class="c"># one can just create a corresponding class:</span>
        <span class="c"># class GUIVariable:</span>
        <span class="c">#     def __init__(self): pass</span>
        <span class="c">#     def attach(self, widget):</span>
        <span class="c">#         self.widget = widget # can be done in make_widget_*</span>
        <span class="c">#     def get(self):</span>
        <span class="c">#         self.widget.get()  # for example</span>
        <span class="c">#     def set(self, value):</span>
        <span class="c">#         self.widget.set(value) # for example</span>

        <span class="n">InputPrm</span><span class="o">.</span><span class="n">__init__</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">name</span><span class="p">,</span> <span class="n">default</span><span class="p">,</span>
                          <span class="n">str2type</span><span class="p">,</span> <span class="n">help</span><span class="p">,</span> <span class="n">unit</span><span class="p">,</span> <span class="n">cmlarg</span><span class="p">)</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">_widget_type</span> <span class="o">=</span> <span class="n">widget_type</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">parent</span> <span class="o">=</span> <span class="n">parent</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">_values</span> <span class="o">=</span> <span class="n">values</span>  <span class="c"># (from, to) interval for parameter</span>

        <span class="bp">self</span><span class="o">.</span><span class="n">widget</span> <span class="o">=</span> <span class="bp">None</span>     <span class="c"># no widget created (yet)</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">_validate</span> <span class="o">=</span> <span class="bp">None</span>  <span class="c"># no validation of answers by default</span>

        <span class="k">if</span> <span class="n">str2type</span> <span class="o">==</span> <span class="n">str2bool</span> <span class="ow">and</span> <span class="bp">self</span><span class="o">.</span><span class="n">_widget_type</span> <span class="o">!=</span> <span class="s">&#39;checkbutton&#39;</span><span class="p">:</span>
            <span class="bp">self</span><span class="o">.</span><span class="n">_widget_type</span> <span class="o">=</span> <span class="s">&#39;checkbutton&#39;</span>
            <span class="c"># no warning because minimal input, just name and a</span>
            <span class="c"># bool value, leads us here - which is okay - all other</span>
            <span class="c"># widgets become entries</span>
</div>
<div class="viewcode-block" id="InputPrmGUI.get_widget_type"><a class="viewcode-back" href="../../TkGUI.html#scitools.TkGUI.InputPrmGUI.get_widget_type">[docs]</a>    <span class="k">def</span> <span class="nf">get_widget_type</span><span class="p">(</span><span class="bp">self</span><span class="p">):</span>  <span class="k">return</span> <span class="bp">self</span><span class="o">.</span><span class="n">_widget_type</span></div>
    <span class="n">widget_type</span> <span class="o">=</span> <span class="nb">property</span><span class="p">(</span><span class="n">fget</span><span class="o">=</span><span class="n">get_widget_type</span><span class="p">)</span> <span class="c"># read-only</span>

<div class="viewcode-block" id="InputPrmGUI.make_GUI_variable_Tk"><a class="viewcode-back" href="../../TkGUI.html#scitools.TkGUI.InputPrmGUI.make_GUI_variable_Tk">[docs]</a>    <span class="k">def</span> <span class="nf">make_GUI_variable_Tk</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">str2type</span><span class="p">,</span> <span class="n">unit</span><span class="p">,</span> <span class="n">name</span><span class="p">):</span>
        <span class="sd">&quot;&quot;&quot;</span>
<span class="sd">        Bind self._v to a variable with set and get methods for</span>
<span class="sd">        setting and getting the value in/from a GUI.</span>
<span class="sd">        &quot;&quot;&quot;</span>
        <span class="k">if</span> <span class="n">unit</span> <span class="ow">is</span> <span class="ow">not</span> <span class="bp">None</span><span class="p">:</span>
            <span class="bp">self</span><span class="o">.</span><span class="n">_v</span> <span class="o">=</span> <span class="n">Tkinter</span><span class="o">.</span><span class="n">StringVar</span><span class="p">()</span>  <span class="c"># value with unit</span>
        <span class="k">else</span><span class="p">:</span>
            <span class="k">if</span> <span class="n">str2type</span> <span class="o">==</span> <span class="nb">float</span><span class="p">:</span>
                <span class="bp">self</span><span class="o">.</span><span class="n">_v</span> <span class="o">=</span> <span class="n">Tkinter</span><span class="o">.</span><span class="n">DoubleVar</span><span class="p">()</span>
                <span class="bp">self</span><span class="o">.</span><span class="n">_validate</span> <span class="o">=</span> <span class="p">{</span><span class="s">&#39;validator&#39;</span> <span class="p">:</span> <span class="s">&#39;real&#39;</span><span class="p">}</span>
            <span class="k">elif</span> <span class="n">str2type</span> <span class="o">==</span> <span class="nb">str</span><span class="p">:</span>
                <span class="bp">self</span><span class="o">.</span><span class="n">_v</span> <span class="o">=</span> <span class="n">Tkinter</span><span class="o">.</span><span class="n">StringVar</span><span class="p">()</span>
            <span class="k">elif</span> <span class="n">str2type</span> <span class="o">==</span> <span class="nb">int</span><span class="p">:</span>
                <span class="bp">self</span><span class="o">.</span><span class="n">_v</span> <span class="o">=</span> <span class="n">Tkinter</span><span class="o">.</span><span class="n">IntVar</span><span class="p">()</span>
                <span class="bp">self</span><span class="o">.</span><span class="n">_validate</span> <span class="o">=</span> <span class="p">{</span><span class="s">&#39;validator&#39;</span> <span class="p">:</span> <span class="s">&#39;int&#39;</span><span class="p">}</span>
            <span class="k">elif</span> <span class="n">str2type</span> <span class="o">==</span> <span class="n">str2bool</span><span class="p">:</span>
                <span class="bp">self</span><span class="o">.</span><span class="n">_v</span> <span class="o">=</span> <span class="n">Tkinter</span><span class="o">.</span><span class="n">StringVar</span><span class="p">()</span>
            <span class="k">elif</span> <span class="n">str2type</span> <span class="o">==</span> <span class="nb">complex</span><span class="p">:</span>
                <span class="bp">self</span><span class="o">.</span><span class="n">_v</span> <span class="o">=</span> <span class="n">Tkinter</span><span class="o">.</span><span class="n">StringVar</span><span class="p">()</span>
            <span class="k">elif</span> <span class="n">str2type</span> <span class="o">==</span> <span class="n">str2obj</span><span class="p">:</span>
                <span class="bp">self</span><span class="o">.</span><span class="n">_v</span> <span class="o">=</span> <span class="n">Tkinter</span><span class="o">.</span><span class="n">StringVar</span><span class="p">()</span>
            <span class="k">else</span><span class="p">:</span>
                <span class="k">raise</span> <span class="ne">ValueError</span><span class="p">(</span>
                    <span class="s">&#39;str2type </span><span class="si">%s</span><span class="s"> for parameter </span><span class="si">%s</span><span class="s"> is not supported&#39;</span> <span class="o">%</span> \
                    <span class="p">(</span><span class="n">str2type</span><span class="p">,</span> <span class="n">name</span><span class="p">))</span>
</div>
<div class="viewcode-block" id="InputPrmGUI.make_widget"><a class="viewcode-back" href="../../TkGUI.html#scitools.TkGUI.InputPrmGUI.make_widget">[docs]</a>    <span class="k">def</span> <span class="nf">make_widget</span><span class="p">(</span><span class="bp">self</span><span class="p">):</span>
        <span class="k">if</span> <span class="n">InputPrmGUI</span><span class="o">.</span><span class="n">GUI_toolkit</span><span class="o">.</span><span class="n">startswith</span><span class="p">(</span><span class="s">&#39;Tk&#39;</span><span class="p">):</span>
            <span class="bp">self</span><span class="o">.</span><span class="n">make_widget_Tk</span><span class="p">()</span>
        <span class="k">else</span><span class="p">:</span>
            <span class="k">raise</span> <span class="ne">ValueError</span><span class="p">(</span>
                <span class="s">&#39;The desired GUI toolkit </span><span class="si">%s</span><span class="s"> is not supported&#39;</span> <span class="o">%</span> \
                <span class="n">InputPrmGUI</span><span class="o">.</span><span class="n">GUI_toolkit</span><span class="p">)</span>
</div>
<div class="viewcode-block" id="InputPrmGUI.make_widget_Tk"><a class="viewcode-back" href="../../TkGUI.html#scitools.TkGUI.InputPrmGUI.make_widget_Tk">[docs]</a>    <span class="k">def</span> <span class="nf">make_widget_Tk</span><span class="p">(</span><span class="bp">self</span><span class="p">):</span>
        <span class="sd">&quot;&quot;&quot;Make Tk widget according to self._widget_type.&quot;&quot;&quot;</span>
        <span class="k">if</span> <span class="bp">self</span><span class="o">.</span><span class="n">name</span> <span class="ow">is</span> <span class="bp">None</span><span class="p">:</span>
            <span class="k">raise</span> <span class="ne">TypeError</span><span class="p">(</span><span class="s">&quot;name attribute must be set before &quot;</span>\
                            <span class="s">&quot;widget can be created&quot;</span><span class="p">)</span>
        <span class="k">if</span> <span class="bp">self</span><span class="o">.</span><span class="n">parent</span> <span class="ow">is</span> <span class="bp">None</span><span class="p">:</span>
            <span class="k">raise</span> <span class="ne">TypeError</span><span class="p">(</span><span class="s">&quot;parent attribute must be set before &quot;</span>\
                            <span class="s">&quot;widget can be created&quot;</span><span class="p">)</span>
        <span class="c"># consistency/type check of values, if it is supplied:</span>
        <span class="k">if</span> <span class="bp">self</span><span class="o">.</span><span class="n">_values</span> <span class="ow">is</span> <span class="ow">not</span> <span class="bp">None</span><span class="p">:</span>
            <span class="k">if</span> <span class="nb">type</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">_values</span><span class="p">)</span> <span class="o">!=</span> <span class="nb">type</span><span class="p">([])</span> <span class="ow">and</span> \
               <span class="nb">type</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">_values</span><span class="p">)</span> <span class="o">!=</span> <span class="nb">type</span><span class="p">(()):</span>
                <span class="k">raise</span> <span class="ne">TypeError</span><span class="p">(</span><span class="s">&quot;values attribute must be list or tuple&quot;</span><span class="p">)</span>

        <span class="k">if</span> <span class="bp">self</span><span class="o">.</span><span class="n">unit</span> <span class="ow">is</span> <span class="bp">None</span><span class="p">:</span>
            <span class="n">label</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">name</span>
        <span class="k">else</span><span class="p">:</span>
            <span class="n">label</span> <span class="o">=</span> <span class="s">&#39;</span><span class="si">%s</span><span class="s"> (</span><span class="si">%s</span><span class="s">)&#39;</span> <span class="o">%</span> <span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">name</span><span class="p">,</span> <span class="bp">self</span><span class="o">.</span><span class="n">unit</span><span class="p">)</span>

        <span class="k">if</span> <span class="bp">self</span><span class="o">.</span><span class="n">_widget_type</span> <span class="o">==</span> <span class="s">&#39;entry&#39;</span><span class="p">:</span>
            <span class="k">if</span> <span class="bp">self</span><span class="o">.</span><span class="n">_validate</span> <span class="ow">is</span> <span class="ow">not</span> <span class="bp">None</span> <span class="ow">and</span> <span class="bp">self</span><span class="o">.</span><span class="n">_values</span> <span class="ow">is</span> <span class="ow">not</span> <span class="bp">None</span><span class="p">:</span>
                <span class="bp">self</span><span class="o">.</span><span class="n">_validate</span><span class="p">[</span><span class="s">&#39;min&#39;</span><span class="p">]</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">_values</span><span class="p">[</span><span class="mi">0</span><span class="p">]</span>
                <span class="bp">self</span><span class="o">.</span><span class="n">_validate</span><span class="p">[</span><span class="s">&#39;max&#39;</span><span class="p">]</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">_values</span><span class="p">[</span><span class="mi">1</span><span class="p">]</span>
            <span class="bp">self</span><span class="o">.</span><span class="n">widget</span> <span class="o">=</span> <span class="n">Pmw</span><span class="o">.</span><span class="n">EntryField</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">parent</span><span class="p">,</span>
                            <span class="n">labelpos</span><span class="o">=</span><span class="s">&#39;w&#39;</span><span class="p">,</span>
                            <span class="n">label_text</span><span class="o">=</span><span class="n">label</span><span class="p">,</span>
                            <span class="n">validate</span><span class="o">=</span><span class="bp">self</span><span class="o">.</span><span class="n">_validate</span><span class="p">,</span>
                            <span class="n">entry_width</span><span class="o">=</span><span class="mi">15</span><span class="p">,</span>
                            <span class="n">entry_textvariable</span><span class="o">=</span><span class="bp">self</span><span class="o">.</span><span class="n">_v</span><span class="p">)</span>
        <span class="k">elif</span> <span class="bp">self</span><span class="o">.</span><span class="n">_widget_type</span> <span class="o">==</span> <span class="s">&#39;slider&#39;</span><span class="p">:</span>
            <span class="c"># we require values:</span>
            <span class="k">if</span> <span class="bp">self</span><span class="o">.</span><span class="n">_values</span> <span class="ow">is</span> <span class="bp">None</span><span class="p">:</span>
                <span class="k">raise</span> <span class="ne">TypeError</span><span class="p">(</span>
                    <span class="s">&quot;values attribute must be set for slider &#39;</span><span class="si">%s</span><span class="s">&#39;&quot;</span> <span class="o">%</span> \
                    <span class="bp">self</span><span class="o">.</span><span class="n">name</span><span class="p">)</span>

            <span class="nb">min</span> <span class="o">=</span> <span class="nb">float</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">_values</span><span class="p">[</span><span class="mi">0</span><span class="p">]);</span> <span class="nb">max</span> <span class="o">=</span> <span class="nb">float</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">_values</span><span class="p">[</span><span class="mi">1</span><span class="p">])</span>
            <span class="k">try</span><span class="p">:</span>
                <span class="n">step</span> <span class="o">=</span> <span class="nb">float</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">_values</span><span class="p">[</span><span class="mi">2</span><span class="p">])</span>  <span class="c"># try if present</span>
            <span class="k">except</span><span class="p">:</span>
                <span class="n">step</span> <span class="o">=</span> <span class="p">(</span><span class="nb">max</span> <span class="o">-</span> <span class="nb">min</span><span class="p">)</span><span class="o">/</span><span class="mf">100.0</span>       <span class="c"># default</span>
            <span class="bp">self</span><span class="o">.</span><span class="n">widget</span> <span class="o">=</span> <span class="n">Tkinter</span><span class="o">.</span><span class="n">Scale</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">parent</span><span class="p">,</span>
                     <span class="n">orient</span><span class="o">=</span><span class="s">&#39;horizontal&#39;</span><span class="p">,</span>
                     <span class="n">from_</span><span class="o">=</span><span class="nb">min</span><span class="p">,</span> <span class="n">to</span><span class="o">=</span><span class="nb">max</span><span class="p">,</span>
                     <span class="n">tickinterval</span><span class="o">=</span><span class="p">(</span><span class="nb">max</span> <span class="o">-</span> <span class="nb">min</span><span class="p">)</span><span class="o">/</span><span class="mf">5.0</span><span class="p">,</span>
                     <span class="n">resolution</span><span class="o">=</span><span class="n">step</span><span class="p">,</span>
                     <span class="n">label</span><span class="o">=</span><span class="n">label</span><span class="p">,</span>
                     <span class="c">#font=&quot;helvetica 12 italic&quot;,</span>
                     <span class="n">length</span><span class="o">=</span><span class="mi">300</span><span class="p">,</span>
                     <span class="n">variable</span><span class="o">=</span><span class="bp">self</span><span class="o">.</span><span class="n">_v</span><span class="p">)</span>
        <span class="k">elif</span> <span class="bp">self</span><span class="o">.</span><span class="n">_widget_type</span> <span class="o">==</span> <span class="s">&#39;option&#39;</span><span class="p">:</span>
            <span class="c"># we require values, which now contains the option values</span>
            <span class="k">if</span> <span class="bp">self</span><span class="o">.</span><span class="n">_values</span> <span class="ow">is</span> <span class="bp">None</span><span class="p">:</span>
                <span class="k">raise</span> <span class="ne">TypeError</span><span class="p">(</span>
                    <span class="s">&quot;values attribute must be set for option menu &#39;</span><span class="si">%s</span><span class="s">&#39;&quot;</span> <span class="o">%</span> \
                    <span class="bp">self</span><span class="o">.</span><span class="n">name</span><span class="p">)</span>

            <span class="bp">self</span><span class="o">.</span><span class="n">widget</span> <span class="o">=</span> <span class="n">Pmw</span><span class="o">.</span><span class="n">OptionMenu</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">parent</span><span class="p">,</span>
               <span class="n">labelpos</span><span class="o">=</span><span class="s">&#39;w&#39;</span><span class="p">,</span>  <span class="c"># n, nw, ne, e and so on</span>
               <span class="n">label_text</span><span class="o">=</span><span class="n">label</span><span class="p">,</span>
               <span class="n">items</span><span class="o">=</span><span class="bp">self</span><span class="o">.</span><span class="n">_values</span><span class="p">,</span>
               <span class="n">menubutton_textvariable</span><span class="o">=</span><span class="bp">self</span><span class="o">.</span><span class="n">_v</span>
               <span class="p">)</span>
        <span class="k">elif</span> <span class="bp">self</span><span class="o">.</span><span class="n">_widget_type</span> <span class="o">==</span> <span class="s">&#39;checkbutton&#39;</span><span class="p">:</span>
            <span class="bp">self</span><span class="o">.</span><span class="n">widget</span> <span class="o">=</span> <span class="n">Tkinter</span><span class="o">.</span><span class="n">Checkbutton</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">parent</span><span class="p">,</span>
                                              <span class="n">text</span><span class="o">=</span><span class="n">label</span><span class="p">,</span>
                                              <span class="n">variable</span><span class="o">=</span><span class="bp">self</span><span class="o">.</span><span class="n">_v</span><span class="p">)</span>
        <span class="c"># no packing of widgets</span>
        <span class="k">return</span> <span class="bp">self</span><span class="o">.</span><span class="n">widget</span>  <span class="c"># if desired (it&#39;s stored in the class too)</span>
</div>
<div class="viewcode-block" id="InputPrmGUI.get"><a class="viewcode-back" href="../../TkGUI.html#scitools.TkGUI.InputPrmGUI.get">[docs]</a>    <span class="k">def</span> <span class="nf">get</span><span class="p">(</span><span class="bp">self</span><span class="p">):</span>
        <span class="sd">&quot;&quot;&quot;</span>
<span class="sd">        Get GUI text/number, handle special input like numbers</span>
<span class="sd">        with units, if necessary.</span>
<span class="sd">        &quot;&quot;&quot;</span>
        <span class="c"># self.str2type(self._scan(gui)) is sufficient here</span>
        <span class="c"># but we check if we have a unit and then if the unit</span>
        <span class="c"># is registered:</span>
        <span class="k">try</span><span class="p">:</span>
            <span class="n">gui</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">_v</span><span class="o">.</span><span class="n">get</span><span class="p">()</span>  <span class="c"># fails if value has unit</span>
        <span class="k">except</span> <span class="ne">ValueError</span><span class="p">,</span> <span class="n">msg</span><span class="p">:</span>
            <span class="k">if</span> <span class="bp">self</span><span class="o">.</span><span class="n">unit</span> <span class="ow">is</span> <span class="bp">None</span><span class="p">:</span>
                <span class="k">print</span> <span class="n">msg</span><span class="p">,</span> <span class="s">&#39;</span><span class="se">\n</span><span class="s">value with unit, but no registered unit!&#39;</span>
                <span class="n">sys</span><span class="o">.</span><span class="n">exit</span><span class="p">(</span><span class="mi">1</span><span class="p">)</span>
            <span class="c"># else: ok, go on with self._scan and interpret</span>

        <span class="n">r</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">_scan</span><span class="p">(</span><span class="n">gui</span><span class="p">)</span>
        <span class="k">return</span> <span class="n">r</span>
</div>
<div class="viewcode-block" id="InputPrmGUI.set"><a class="viewcode-back" href="../../TkGUI.html#scitools.TkGUI.InputPrmGUI.set">[docs]</a>    <span class="k">def</span> <span class="nf">set</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">value</span><span class="p">):</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">_v</span><span class="o">.</span><span class="n">set</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">str2type</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">_scan</span><span class="p">(</span><span class="n">value</span><span class="p">)))</span>
</div>
<div class="viewcode-block" id="InputPrmGUI.__repr__"><a class="viewcode-back" href="../../TkGUI.html#scitools.TkGUI.InputPrmGUI.__repr__">[docs]</a>    <span class="k">def</span> <span class="nf">__repr__</span><span class="p">(</span><span class="bp">self</span><span class="p">):</span>
        <span class="sd">&quot;&quot;&quot;Application of eval to this output creates the object.&quot;&quot;&quot;</span>
        <span class="k">return</span> <span class="s">&quot;InputPrmGUI(name=&#39;</span><span class="si">%s</span><span class="s">&#39;, default=</span><span class="si">%s</span><span class="s">, str2type=</span><span class="si">%s</span><span class="s">, &quot;</span>\
               <span class="s">&quot;widget_type=&#39;</span><span class="si">%s</span><span class="s">&#39;, parent=None, values=</span><span class="si">%s</span><span class="s">, &quot;</span>\
               <span class="s">&quot;help=</span><span class="si">%s</span><span class="s">, unit=</span><span class="si">%s</span><span class="s">, cmlarg=</span><span class="si">%s</span><span class="s">)&quot;</span> <span class="o">%</span> \
               <span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">name</span><span class="p">,</span> <span class="bp">self</span><span class="o">.</span><span class="n">__str__</span><span class="p">(),</span> <span class="bp">self</span><span class="o">.</span><span class="n">str2type</span><span class="o">.</span><span class="n">__name__</span><span class="p">,</span>
                <span class="bp">self</span><span class="o">.</span><span class="n">_widget_type</span><span class="p">,</span> <span class="nb">str</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">_values</span><span class="p">),</span>
                <span class="bp">self</span><span class="o">.</span><span class="n">help</span><span class="p">,</span> <span class="bp">self</span><span class="o">.</span><span class="n">unit</span><span class="p">,</span> <span class="bp">self</span><span class="o">.</span><span class="n">cmlarg</span><span class="p">)</span>

</div></div>
<div class="viewcode-block" id="InputPrmCGI"><a class="viewcode-back" href="../../TkGUI.html#scitools.TkGUI.InputPrmCGI">[docs]</a><span class="k">class</span> <span class="nc">InputPrmCGI</span><span class="p">(</span><span class="n">InputPrm</span><span class="p">):</span>
    <span class="sd">&quot;&quot;&quot;Represent a parameter by a form variable in HTML.&quot;&quot;&quot;</span>
<div class="viewcode-block" id="InputPrmCGI.__init__"><a class="viewcode-back" href="../../TkGUI.html#scitools.TkGUI.InputPrmCGI.__init__">[docs]</a>    <span class="k">def</span> <span class="nf">__init__</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">name</span><span class="o">=</span><span class="bp">None</span><span class="p">,</span> <span class="n">default</span><span class="o">=</span><span class="mf">0.0</span><span class="p">,</span> <span class="n">str2type</span><span class="o">=</span><span class="bp">None</span><span class="p">,</span>
                 <span class="n">widget_type</span><span class="o">=</span><span class="s">&#39;entry&#39;</span><span class="p">,</span> <span class="n">values</span><span class="o">=</span><span class="bp">None</span><span class="p">,</span> <span class="n">form</span><span class="o">=</span><span class="bp">None</span><span class="p">,</span>
                 <span class="n">help</span><span class="o">=</span><span class="bp">None</span><span class="p">,</span> <span class="n">unit</span><span class="o">=</span><span class="bp">None</span><span class="p">,</span> <span class="n">cmlarg</span><span class="o">=</span><span class="bp">None</span><span class="p">):</span>
        <span class="sd">&quot;&quot;&quot;</span>
<span class="sd">        default            default value</span>
<span class="sd">        str2type           function from string to type</span>
<span class="sd">        name               name of parameter</span>
<span class="sd">        widget_type        entry, slider, option, checkbutton</span>
<span class="sd">        values             option values</span>
<span class="sd">        form               cgi.FieldStorage object</span>
<span class="sd">        help               description of parameter</span>
<span class="sd">        unit               physical unit (dimension)</span>
<span class="sd">        cmlarg             command-line argument for sending</span>
<span class="sd">                           this prm to an external program</span>
<span class="sd">        &quot;&quot;&quot;</span>

        <span class="n">InputPrm</span><span class="o">.</span><span class="n">__init__</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">name</span><span class="p">,</span> <span class="n">default</span><span class="p">,</span> <span class="n">str2type</span><span class="p">,</span>
                          <span class="n">help</span><span class="p">,</span> <span class="n">unit</span><span class="p">,</span> <span class="n">cmlarg</span><span class="p">)</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">_widget_type</span> <span class="o">=</span> <span class="n">widget_type</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">_form</span> <span class="o">=</span> <span class="n">form</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">_values</span> <span class="o">=</span> <span class="n">values</span>
</div>
<div class="viewcode-block" id="InputPrmCGI.make_form_entry"><a class="viewcode-back" href="../../TkGUI.html#scitools.TkGUI.InputPrmCGI.make_form_entry">[docs]</a>    <span class="k">def</span> <span class="nf">make_form_entry</span><span class="p">(</span><span class="bp">self</span><span class="p">):</span>
        <span class="sd">&quot;&quot;&quot;Write the form&#39;s input field, according to widget_type.&quot;&quot;&quot;</span>
        <span class="k">if</span> <span class="bp">self</span><span class="o">.</span><span class="n">name</span> <span class="ow">is</span> <span class="bp">None</span><span class="p">:</span>
            <span class="k">raise</span> <span class="ne">TypeError</span><span class="p">(</span><span class="s">&quot;name attribute must be set before &quot;</span>\
                            <span class="s">&quot;widget can be created&quot;</span><span class="p">)</span>

        <span class="n">value</span> <span class="o">=</span> <span class="nb">str</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">get</span><span class="p">())</span>

        <span class="n">s</span> <span class="o">=</span> <span class="s">&quot;&quot;</span>  <span class="c"># HTML code to be returned is stored in s</span>
        <span class="k">if</span> <span class="bp">self</span><span class="o">.</span><span class="n">_widget_type</span> <span class="o">==</span> <span class="s">&#39;entry&#39;</span> <span class="ow">or</span> <span class="bp">self</span><span class="o">.</span><span class="n">_widget_type</span> <span class="o">==</span> <span class="s">&#39;slider&#39;</span><span class="p">:</span>
            <span class="n">s</span> <span class="o">+=</span> <span class="s">&quot;&quot;&quot;&lt;input type=&quot;text&quot; name=&quot;</span><span class="si">%s</span><span class="s">&quot; size=15 value=&quot;</span><span class="si">%s</span><span class="s">&quot;&gt;&quot;&quot;&quot;</span> <span class="o">%</span> \
                 <span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">name</span><span class="p">,</span> <span class="n">value</span><span class="p">)</span>
        <span class="k">elif</span> <span class="bp">self</span><span class="o">.</span><span class="n">_widget_type</span> <span class="o">==</span> <span class="s">&#39;option&#39;</span><span class="p">:</span>
            <span class="c"># we require values, which now contains the option values</span>
            <span class="k">if</span> <span class="bp">self</span><span class="o">.</span><span class="n">_values</span> <span class="ow">is</span> <span class="bp">None</span><span class="p">:</span>
                <span class="k">raise</span> <span class="ne">TypeError</span><span class="p">(</span>
                    <span class="s">&quot;values attribute must be set for option menu &#39;</span><span class="si">%s</span><span class="s">&#39;&quot;</span> <span class="o">%</span> \
                    <span class="bp">self</span><span class="o">.</span><span class="n">name</span><span class="p">)</span>

            <span class="n">s</span> <span class="o">+=</span> <span class="s">&quot;&quot;&quot;&lt;select name=&quot;</span><span class="si">%s</span><span class="s">&quot; size=1 value=&quot;</span><span class="si">%s</span><span class="s">&quot;&gt;</span><span class="se">\n</span><span class="s">&quot;&quot;&quot;</span> <span class="o">%</span> \
                 <span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">name</span><span class="p">,</span> <span class="n">value</span><span class="p">)</span>
            <span class="k">for</span> <span class="n">v</span> <span class="ow">in</span> <span class="bp">self</span><span class="o">.</span><span class="n">_values</span><span class="p">:</span>
                <span class="n">s</span> <span class="o">+=</span> <span class="s">&quot;&quot;&quot;&lt;option value=&quot;</span><span class="si">%s</span><span class="s">&quot;&gt;</span><span class="si">%s</span><span class="s"> &lt;/option&gt;</span><span class="se">\n</span><span class="s">&quot;&quot;&quot;</span> <span class="o">%</span> \
                     <span class="p">(</span><span class="n">v</span><span class="p">,</span><span class="n">v</span><span class="p">)</span>
            <span class="n">s</span> <span class="o">+=</span> <span class="s">&quot;&quot;&quot;&lt;/select&gt;&lt;br&gt;</span><span class="se">\n</span><span class="s">&quot;&quot;&quot;</span>

        <span class="k">elif</span> <span class="bp">self</span><span class="o">.</span><span class="n">_widget_type</span> <span class="o">==</span> <span class="s">&#39;checkbutton&#39;</span><span class="p">:</span>
            <span class="n">s</span> <span class="o">+=</span> <span class="s">&quot;&quot;&quot;&lt;input type=&quot;checkbox&quot; name=&quot;</span><span class="si">%s</span><span class="s">&quot; value=&quot;</span><span class="si">%s</span><span class="s">&quot;&gt;&quot;&quot;&quot;</span>\
                 <span class="sd">&quot;&quot;&quot;&amp;nbsp; &lt;br&gt;\n&quot;&quot;&quot;</span> <span class="o">%</span> \
                 <span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">name</span><span class="p">,</span> <span class="n">value</span><span class="p">)</span>

        <span class="k">return</span> <span class="n">s</span>
</div>
<div class="viewcode-block" id="InputPrmCGI.get"><a class="viewcode-back" href="../../TkGUI.html#scitools.TkGUI.InputPrmCGI.get">[docs]</a>    <span class="k">def</span> <span class="nf">get</span><span class="p">(</span><span class="bp">self</span><span class="p">):</span>
        <span class="k">if</span> <span class="bp">self</span><span class="o">.</span><span class="n">_form</span> <span class="ow">is</span> <span class="ow">not</span> <span class="bp">None</span><span class="p">:</span>
            <span class="n">InputPrm</span><span class="o">.</span><span class="n">set</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span>\
                <span class="bp">self</span><span class="o">.</span><span class="n">_form</span><span class="o">.</span><span class="n">getvalue</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">name</span><span class="p">,</span> <span class="nb">str</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">_v</span><span class="p">)))</span>
            <span class="c"># InputPrm.set handles units</span>

        <span class="k">return</span> <span class="bp">self</span><span class="o">.</span><span class="n">_v</span>

    <span class="c"># just inherit def set(self, value):</span>

</div>
<div class="viewcode-block" id="InputPrmCGI.__repr__"><a class="viewcode-back" href="../../TkGUI.html#scitools.TkGUI.InputPrmCGI.__repr__">[docs]</a>    <span class="k">def</span> <span class="nf">__repr__</span><span class="p">(</span><span class="bp">self</span><span class="p">):</span>
        <span class="sd">&quot;&quot;&quot;Application of eval to this output creates the object.&quot;&quot;&quot;</span>
        <span class="k">return</span> <span class="s">&quot;InputPrmCGI(name=&#39;</span><span class="si">%s</span><span class="s">&#39;, default=</span><span class="si">%s</span><span class="s">, str2type=</span><span class="si">%s</span><span class="s">, &quot;</span>\
               <span class="s">&quot;widget_type=&#39;</span><span class="si">%s</span><span class="s">&#39;, form=None, values=</span><span class="si">%s</span><span class="s">, &quot;</span>\
               <span class="s">&quot;help=</span><span class="si">%s</span><span class="s">, unit=</span><span class="si">%s</span><span class="s">, cmlarg=</span><span class="si">%s</span><span class="s">)&quot;</span> <span class="o">%</span> \
               <span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">name</span><span class="p">,</span> <span class="bp">self</span><span class="o">.</span><span class="n">__str__</span><span class="p">(),</span> <span class="bp">self</span><span class="o">.</span><span class="n">str2type</span><span class="o">.</span><span class="n">__name__</span><span class="p">,</span>
                <span class="bp">self</span><span class="o">.</span><span class="n">_widget_type</span><span class="p">,</span> <span class="nb">str</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">_values</span><span class="p">),</span>
                <span class="bp">self</span><span class="o">.</span><span class="n">help</span><span class="p">,</span> <span class="bp">self</span><span class="o">.</span><span class="n">unit</span><span class="p">,</span> <span class="bp">self</span><span class="o">.</span><span class="n">cmlarg</span><span class="p">)</span>

</div></div>
<div class="viewcode-block" id="createInputPrm"><a class="viewcode-back" href="../../TkGUI.html#scitools.TkGUI.createInputPrm">[docs]</a><span class="k">def</span> <span class="nf">createInputPrm</span><span class="p">(</span><span class="n">interface</span><span class="p">,</span> <span class="n">name</span><span class="p">,</span> <span class="n">default</span><span class="p">,</span> <span class="n">str2type</span><span class="o">=</span><span class="bp">None</span><span class="p">,</span>
                   <span class="n">widget_type</span><span class="o">=</span><span class="s">&#39;entry&#39;</span><span class="p">,</span> <span class="n">values</span><span class="o">=</span><span class="bp">None</span><span class="p">,</span>
                   <span class="n">parent</span><span class="o">=</span><span class="bp">None</span><span class="p">,</span> <span class="n">form</span><span class="o">=</span><span class="bp">None</span><span class="p">,</span>
                   <span class="n">help</span><span class="o">=</span><span class="bp">None</span><span class="p">,</span> <span class="n">unit</span><span class="o">=</span><span class="bp">None</span><span class="p">,</span> <span class="n">cmlarg</span><span class="o">=</span><span class="bp">None</span><span class="p">):</span>
    <span class="sd">&quot;&quot;&quot;Unified interface to parameter classes InputPrm/GUI/CGI.&quot;&quot;&quot;</span>
    <span class="k">if</span> <span class="n">interface</span> <span class="o">==</span> <span class="s">&#39;&#39;</span> <span class="ow">or</span> <span class="n">interface</span> <span class="o">==</span> <span class="s">&#39;plain&#39;</span><span class="p">:</span>
        <span class="n">p</span> <span class="o">=</span> <span class="n">InputPrm</span><span class="p">(</span><span class="n">name</span><span class="o">=</span><span class="n">name</span><span class="p">,</span> <span class="n">default</span><span class="o">=</span><span class="n">default</span><span class="p">,</span>
                     <span class="n">str2type</span><span class="o">=</span><span class="n">str2type</span><span class="p">,</span>
                     <span class="n">help</span><span class="o">=</span><span class="n">help</span><span class="p">,</span> <span class="n">unit</span><span class="o">=</span><span class="n">unit</span><span class="p">,</span> <span class="n">cmlarg</span><span class="o">=</span><span class="n">cmlarg</span><span class="p">)</span>
    <span class="k">elif</span> <span class="n">interface</span> <span class="o">==</span> <span class="s">&#39;GUI&#39;</span><span class="p">:</span>
        <span class="n">p</span> <span class="o">=</span> <span class="n">InputPrmGUI</span><span class="p">(</span><span class="n">name</span><span class="o">=</span><span class="n">name</span><span class="p">,</span> <span class="n">default</span><span class="o">=</span><span class="n">default</span><span class="p">,</span>
                        <span class="n">str2type</span><span class="o">=</span><span class="n">str2type</span><span class="p">,</span>
                        <span class="n">widget_type</span><span class="o">=</span><span class="n">widget_type</span><span class="p">,</span>
                        <span class="n">values</span><span class="o">=</span><span class="n">values</span><span class="p">,</span> <span class="n">parent</span><span class="o">=</span><span class="n">parent</span><span class="p">,</span>
                        <span class="n">help</span><span class="o">=</span><span class="n">help</span><span class="p">,</span> <span class="n">unit</span><span class="o">=</span><span class="n">unit</span><span class="p">,</span> <span class="n">cmlarg</span><span class="o">=</span><span class="n">cmlarg</span><span class="p">)</span>
    <span class="k">elif</span> <span class="n">interface</span> <span class="o">==</span> <span class="s">&#39;CGI&#39;</span><span class="p">:</span>
        <span class="n">p</span> <span class="o">=</span> <span class="n">InputPrmCGI</span><span class="p">(</span><span class="n">name</span><span class="o">=</span><span class="n">name</span><span class="p">,</span> <span class="n">default</span><span class="o">=</span><span class="n">default</span><span class="p">,</span>
                        <span class="n">str2type</span><span class="o">=</span><span class="n">str2type</span><span class="p">,</span>
                        <span class="n">widget_type</span><span class="o">=</span><span class="n">widget_type</span><span class="p">,</span>
                        <span class="n">values</span><span class="o">=</span><span class="n">values</span><span class="p">,</span> <span class="n">form</span><span class="o">=</span><span class="n">form</span><span class="p">,</span>
                        <span class="n">help</span><span class="o">=</span><span class="n">help</span><span class="p">,</span> <span class="n">unit</span><span class="o">=</span><span class="n">unit</span><span class="p">,</span> <span class="n">cmlarg</span><span class="o">=</span><span class="n">cmlarg</span><span class="p">)</span>
    <span class="k">else</span><span class="p">:</span>
        <span class="k">raise</span> <span class="ne">ValueError</span><span class="p">(</span><span class="s">&quot;interface &#39;</span><span class="si">%s</span><span class="s">&#39; not supported&quot;</span> <span class="o">%</span> <span class="n">interface</span><span class="p">)</span>

    <span class="k">return</span> <span class="n">p</span>
</div>
<div class="viewcode-block" id="Parameters"><a class="viewcode-back" href="../../TkGUI.html#scitools.TkGUI.Parameters">[docs]</a><span class="k">class</span> <span class="nc">Parameters</span><span class="p">:</span>
    <span class="sd">&quot;&quot;&quot;</span>
<span class="sd">    Class for holding a set of InputPrm-type parameters.</span>
<span class="sd">    See src/py/examples/simviz/simviz1cp.py for examples</span>
<span class="sd">    on usage.</span>

<span class="sd">    Some attributes may be useful in application code:</span>

<span class="sd">    self.dict is a dictionary of InputPrm-type objects.</span>

<span class="sd">    self.parameters_sequence (and self._seq) is a list of</span>
<span class="sd">    InputPrm-type objects in the sequence they were registered.</span>

<span class="sd">    self.sliders_sequence is a list of InputPrm-type objects,</span>
<span class="sd">    with slider widget representation in a GUI, in the sequence</span>
<span class="sd">    they were registered.</span>
<span class="sd">    self.entries_sequence, self.checkbt_sequence,</span>
<span class="sd">    self.options_sequence are similar for text entries, checkbuttons,</span>
<span class="sd">    and option menus.</span>

<span class="sd">    The self.*_sequence lists can be used to build GUIs or CGI scripts.</span>
<span class="sd">    Normally, this is automated in classes like AutoSimVizGUI and</span>
<span class="sd">    AutoSimVizCGI.</span>
<span class="sd">    &quot;&quot;&quot;</span>
<div class="viewcode-block" id="Parameters.__init__"><a class="viewcode-back" href="../../TkGUI.html#scitools.TkGUI.Parameters.__init__">[docs]</a>    <span class="k">def</span> <span class="nf">__init__</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">interface</span><span class="o">=</span><span class="s">&#39;plain&#39;</span><span class="p">,</span> <span class="n">form</span><span class="o">=</span><span class="bp">None</span><span class="p">,</span> <span class="n">prm_dict</span><span class="o">=</span><span class="p">{}):</span>
        <span class="sd">&quot;&quot;&quot;</span>
<span class="sd">        @param interface: &#39;plain&#39;, &#39;CGI&#39;, or &#39;GUI&#39;</span>
<span class="sd">        @param form: cgi.FieldStorage() object</span>
<span class="sd">        @param prm_dict: dictionary with (name,value) pairs</span>
<span class="sd">        (will be added using the add method)</span>
<span class="sd">        &quot;&quot;&quot;</span>

        <span class="bp">self</span><span class="o">.</span><span class="n">dict</span> <span class="o">=</span> <span class="p">{}</span>  <span class="c"># holds InputPrm/GUI/CGI objects</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">_seq</span> <span class="o">=</span> <span class="p">[]</span>  <span class="c"># holds self.dict items in sequence</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">_interface</span> <span class="o">=</span> <span class="n">interface</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">_form</span> <span class="o">=</span> <span class="n">form</span>  <span class="c"># used for CGI</span>
        <span class="k">for</span> <span class="n">prm</span> <span class="ow">in</span> <span class="n">prm_dict</span><span class="p">:</span>
            <span class="bp">self</span><span class="o">.</span><span class="n">add</span><span class="p">(</span><span class="n">prm</span><span class="p">,</span> <span class="n">prm_dict</span><span class="p">[</span><span class="n">prm</span><span class="p">])</span>
</div>
<div class="viewcode-block" id="Parameters.add"><a class="viewcode-back" href="../../TkGUI.html#scitools.TkGUI.Parameters.add">[docs]</a>    <span class="k">def</span> <span class="nf">add</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">name</span><span class="p">,</span> <span class="n">default</span><span class="p">,</span> <span class="n">str2type</span><span class="o">=</span><span class="bp">None</span><span class="p">,</span>
            <span class="n">widget_type</span><span class="o">=</span><span class="s">&#39;entry&#39;</span><span class="p">,</span> <span class="n">values</span><span class="o">=</span><span class="bp">None</span><span class="p">,</span>
            <span class="n">help</span><span class="o">=</span><span class="bp">None</span><span class="p">,</span> <span class="n">unit</span><span class="o">=</span><span class="bp">None</span><span class="p">,</span> <span class="n">cmlarg</span><span class="o">=</span><span class="bp">None</span><span class="p">):</span>
        <span class="sd">&quot;&quot;&quot;Add a new parameter.&quot;&quot;&quot;</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">dict</span><span class="p">[</span><span class="n">name</span><span class="p">]</span> <span class="o">=</span> <span class="n">createInputPrm</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">_interface</span><span class="p">,</span> <span class="n">name</span><span class="p">,</span>
            <span class="n">default</span><span class="p">,</span> <span class="n">str2type</span><span class="p">,</span> <span class="n">widget_type</span><span class="o">=</span><span class="n">widget_type</span><span class="p">,</span>
            <span class="n">values</span><span class="o">=</span><span class="n">values</span><span class="p">,</span> <span class="n">help</span><span class="o">=</span><span class="n">help</span><span class="p">,</span> <span class="n">unit</span><span class="o">=</span><span class="n">unit</span><span class="p">,</span> <span class="n">cmlarg</span><span class="o">=</span><span class="n">cmlarg</span><span class="p">)</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">_seq</span><span class="o">.</span><span class="n">append</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">dict</span><span class="p">[</span><span class="n">name</span><span class="p">])</span>
</div>
<div class="viewcode-block" id="Parameters.endadd"><a class="viewcode-back" href="../../TkGUI.html#scitools.TkGUI.Parameters.endadd">[docs]</a>    <span class="k">def</span> <span class="nf">endadd</span><span class="p">(</span><span class="bp">self</span><span class="p">):</span>
        <span class="sd">&quot;&quot;&quot;Process parameters, make internal data structures.&quot;&quot;&quot;</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">parameters_sequence</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">_seq</span>
        <span class="k">if</span> <span class="bp">self</span><span class="o">.</span><span class="n">_interface</span> <span class="o">==</span> <span class="s">&#39;GUI&#39;</span><span class="p">:</span>
            <span class="bp">self</span><span class="o">.</span><span class="n">sliders_sequence</span> <span class="o">=</span> <span class="p">[]</span>
            <span class="bp">self</span><span class="o">.</span><span class="n">entries_sequence</span> <span class="o">=</span> <span class="p">[]</span>
            <span class="bp">self</span><span class="o">.</span><span class="n">options_sequence</span> <span class="o">=</span> <span class="p">[]</span>
            <span class="bp">self</span><span class="o">.</span><span class="n">checkbt_sequence</span> <span class="o">=</span> <span class="p">[]</span>
            <span class="k">for</span> <span class="n">p</span> <span class="ow">in</span> <span class="bp">self</span><span class="o">.</span><span class="n">_seq</span><span class="p">:</span>
                <span class="k">if</span> <span class="n">p</span><span class="o">.</span><span class="n">widget_type</span> <span class="o">==</span> <span class="s">&#39;slider&#39;</span><span class="p">:</span>
                    <span class="bp">self</span><span class="o">.</span><span class="n">sliders_sequence</span><span class="o">.</span><span class="n">append</span><span class="p">(</span><span class="n">p</span><span class="p">)</span>  <span class="c"># add instance ref.</span>
                <span class="k">elif</span> <span class="n">p</span><span class="o">.</span><span class="n">widget_type</span> <span class="o">==</span> <span class="s">&#39;entry&#39;</span><span class="p">:</span>
                    <span class="bp">self</span><span class="o">.</span><span class="n">entries_sequence</span><span class="o">.</span><span class="n">append</span><span class="p">(</span><span class="n">p</span><span class="p">)</span>
                <span class="k">elif</span> <span class="n">p</span><span class="o">.</span><span class="n">widget_type</span> <span class="o">==</span> <span class="s">&#39;option&#39;</span><span class="p">:</span>
                    <span class="bp">self</span><span class="o">.</span><span class="n">options_sequence</span><span class="o">.</span><span class="n">append</span><span class="p">(</span><span class="n">p</span><span class="p">)</span>
                <span class="k">elif</span> <span class="n">p</span><span class="o">.</span><span class="n">widget_type</span> <span class="o">==</span> <span class="s">&#39;checkbutton&#39;</span><span class="p">:</span>
                    <span class="bp">self</span><span class="o">.</span><span class="n">checkbt_sequence</span><span class="o">.</span><span class="n">append</span><span class="p">(</span><span class="n">p</span><span class="p">)</span>
                <span class="k">else</span><span class="p">:</span>
                    <span class="k">raise</span> <span class="ne">ValueError</span><span class="p">(</span><span class="s">&#39;unknown widget_type &quot;</span><span class="si">%s</span><span class="s">&quot;&#39;</span> \
                                     <span class="o">%</span> <span class="n">p</span><span class="o">.</span><span class="n">widget_type</span><span class="p">)</span>
        <span class="k">elif</span> <span class="bp">self</span><span class="o">.</span><span class="n">_interface</span> <span class="o">==</span> <span class="s">&#39;CGI&#39;</span><span class="p">:</span>
            <span class="k">for</span> <span class="n">p</span> <span class="ow">in</span> <span class="bp">self</span><span class="o">.</span><span class="n">_seq</span><span class="p">:</span>
                <span class="n">p</span><span class="o">.</span><span class="n">form</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">_form</span>
</div>
<div class="viewcode-block" id="Parameters.__setitem__"><a class="viewcode-back" href="../../TkGUI.html#scitools.TkGUI.Parameters.__setitem__">[docs]</a>    <span class="k">def</span> <span class="nf">__setitem__</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">name</span><span class="p">,</span> <span class="n">value</span><span class="p">):</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">dict</span><span class="p">[</span><span class="n">name</span><span class="p">]</span><span class="o">.</span><span class="n">set</span><span class="p">(</span><span class="n">value</span><span class="p">)</span>
        <span class="k">if</span> <span class="n">name</span> <span class="ow">in</span> <span class="bp">self</span><span class="o">.</span><span class="n">__dict__</span><span class="p">:</span>  <span class="c"># is item attribute too (name2attr)?</span>
            <span class="c"># self.__dict__[name] = value # will not handle string w/unit</span>
            <span class="bp">self</span><span class="o">.</span><span class="n">__dict__</span><span class="p">[</span><span class="n">name</span><span class="p">]</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">dict</span><span class="p">[</span><span class="n">name</span><span class="p">]</span><span class="o">.</span><span class="n">get</span><span class="p">()</span>
</div>
<div class="viewcode-block" id="Parameters.__getitem__"><a class="viewcode-back" href="../../TkGUI.html#scitools.TkGUI.Parameters.__getitem__">[docs]</a>    <span class="k">def</span> <span class="nf">__getitem__</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">name</span><span class="p">):</span>
        <span class="k">return</span> <span class="bp">self</span><span class="o">.</span><span class="n">dict</span><span class="p">[</span><span class="n">name</span><span class="p">]</span><span class="o">.</span><span class="n">get</span><span class="p">()</span>
</div>
<div class="viewcode-block" id="Parameters.keys"><a class="viewcode-back" href="../../TkGUI.html#scitools.TkGUI.Parameters.keys">[docs]</a>    <span class="k">def</span> <span class="nf">keys</span><span class="p">(</span><span class="bp">self</span><span class="p">):</span>
        <span class="sd">&quot;&quot;&quot;</span>
<span class="sd">        Return parameter names. With this method Parameter objects p</span>
<span class="sd">        can be used in dictionary update functions: somedict.update(p).</span>
<span class="sd">        &quot;&quot;&quot;</span>
        <span class="k">return</span> <span class="bp">self</span><span class="o">.</span><span class="n">dict</span><span class="o">.</span><span class="n">keys</span><span class="p">()</span>
</div>
<div class="viewcode-block" id="Parameters.__iter__"><a class="viewcode-back" href="../../TkGUI.html#scitools.TkGUI.Parameters.__iter__">[docs]</a>    <span class="k">def</span> <span class="nf">__iter__</span><span class="p">(</span><span class="bp">self</span><span class="p">):</span>
        <span class="sd">&quot;&quot;&quot;Iterate over keys in self.dict.&quot;&quot;&quot;</span>
        <span class="c"># short cut using generator function</span>
        <span class="k">for</span> <span class="n">name</span> <span class="ow">in</span> <span class="bp">self</span><span class="o">.</span><span class="n">dict</span><span class="p">:</span>
            <span class="k">yield</span> <span class="n">name</span>
</div>
<div class="viewcode-block" id="Parameters.get"><a class="viewcode-back" href="../../TkGUI.html#scitools.TkGUI.Parameters.get">[docs]</a>    <span class="k">def</span> <span class="nf">get</span><span class="p">(</span><span class="bp">self</span><span class="p">):</span>
        <span class="sd">&quot;&quot;&quot;Return dictionary with (name,value) pairs.&quot;&quot;&quot;</span>
        <span class="n">d</span> <span class="o">=</span> <span class="p">{}</span>
        <span class="k">for</span> <span class="n">name</span> <span class="ow">in</span> <span class="bp">self</span><span class="p">:</span>
            <span class="n">d</span><span class="p">[</span><span class="n">name</span><span class="p">]</span> <span class="o">=</span> <span class="bp">self</span><span class="p">[</span><span class="n">name</span><span class="p">]</span>  <span class="c"># same as self.dict[name].get()</span>
        <span class="k">return</span> <span class="n">d</span>
</div>
<div class="viewcode-block" id="Parameters.name2attr"><a class="viewcode-back" href="../../TkGUI.html#scitools.TkGUI.Parameters.name2attr">[docs]</a>    <span class="k">def</span> <span class="nf">name2attr</span><span class="p">(</span><span class="bp">self</span><span class="p">):</span>
        <span class="sd">&quot;&quot;&quot;</span>
<span class="sd">        Turn all item keys into attributes.</span>
<span class="sd">        Warning: values are copied! __setitem__ and</span>
<span class="sd">        __setattr__ (or properties) must</span>
<span class="sd">        take care of parallel updates.</span>
<span class="sd">        &quot;&quot;&quot;</span>
        <span class="k">for</span> <span class="n">name</span> <span class="ow">in</span> <span class="bp">self</span><span class="o">.</span><span class="n">dict</span><span class="p">:</span>
            <span class="bp">self</span><span class="o">.</span><span class="n">__dict__</span><span class="p">[</span><span class="n">name</span><span class="p">]</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">dict</span><span class="p">[</span><span class="n">name</span><span class="p">]</span><span class="o">.</span><span class="n">get</span><span class="p">()</span>
</div>
<div class="viewcode-block" id="Parameters.__setattr__"><a class="viewcode-back" href="../../TkGUI.html#scitools.TkGUI.Parameters.__setattr__">[docs]</a>    <span class="k">def</span> <span class="nf">__setattr__</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">name</span><span class="p">,</span> <span class="n">value</span><span class="p">):</span>
        <span class="sd">&quot;&quot;&quot;</span>
<span class="sd">        If name2attr is called, self.m = 2.3 (using this</span>
<span class="sd">        function) is safe, because this also implies update of</span>
<span class="sd">        the corresponding InputPrm-type object in self.dict.</span>
<span class="sd">        &quot;&quot;&quot;</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">__dict__</span><span class="p">[</span><span class="n">name</span><span class="p">]</span> <span class="o">=</span> <span class="n">value</span>
        <span class="k">if</span> <span class="n">name</span> <span class="ow">in</span> <span class="bp">self</span><span class="o">.</span><span class="n">dict</span><span class="p">:</span>
            <span class="bp">self</span><span class="o">.</span><span class="n">dict</span><span class="p">[</span><span class="n">name</span><span class="p">]</span><span class="o">.</span><span class="n">set</span><span class="p">(</span><span class="n">value</span><span class="p">)</span>
        <span class="c">#if str(a) in self.dict:</span>
        <span class="c">#    self.dict[str(a)].set(value)</span>
</div>
<div class="viewcode-block" id="Parameters.parse_options"><a class="viewcode-back" href="../../TkGUI.html#scitools.TkGUI.Parameters.parse_options">[docs]</a>    <span class="k">def</span> <span class="nf">parse_options</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">argv</span><span class="p">):</span>
        <span class="sd">&quot;&quot;&quot;</span>
<span class="sd">        Examine the command line and for each -opt val pair,</span>
<span class="sd">        set the value of parameter opt to val, if opt is a</span>
<span class="sd">        registered parameter.</span>
<span class="sd">        argv is typically sys.argv[1:]</span>
<span class="sd">        Note that the name of a parameter may contain blanks.</span>
<span class="sd">        A blank is replaced by two underscores in the command-line</span>
<span class="sd">        options.</span>
<span class="sd">        &quot;&quot;&quot;</span>
        <span class="n">p</span> <span class="o">=</span> <span class="n">scitools</span><span class="o">.</span><span class="n">misc</span><span class="o">.</span><span class="n">cmldict</span><span class="p">(</span><span class="n">argv</span><span class="p">,</span> <span class="n">cmlargs</span><span class="o">=</span><span class="bp">None</span><span class="p">,</span> <span class="n">validity</span><span class="o">=</span><span class="mi">0</span><span class="p">)</span>
        <span class="c"># p[key] holds all command-line args, we are only interested</span>
        <span class="c"># in those keys corresponding to self.dict.keys()</span>
        <span class="k">for</span> <span class="n">key</span> <span class="ow">in</span> <span class="n">p</span><span class="o">.</span><span class="n">keys</span><span class="p">():</span>
            <span class="k">if</span> <span class="n">key</span><span class="o">.</span><span class="n">find</span><span class="p">(</span><span class="s">&#39;__&#39;</span><span class="p">)</span> <span class="o">!=</span> <span class="o">-</span><span class="mi">1</span><span class="p">:</span>
                <span class="n">key_blanks</span> <span class="o">=</span> <span class="n">key</span><span class="o">.</span><span class="n">replace</span><span class="p">(</span><span class="s">&#39;__&#39;</span><span class="p">,</span> <span class="s">&#39; &#39;</span><span class="p">)</span>
            <span class="k">else</span><span class="p">:</span>
                <span class="n">key_blanks</span> <span class="o">=</span> <span class="n">key</span>
            <span class="k">if</span> <span class="n">key_blanks</span> <span class="ow">in</span> <span class="bp">self</span><span class="o">.</span><span class="n">dict</span><span class="p">:</span>
                <span class="bp">self</span><span class="o">.</span><span class="n">dict</span><span class="p">[</span><span class="n">key_blanks</span><span class="p">]</span><span class="o">.</span><span class="n">set</span><span class="p">(</span><span class="n">p</span><span class="p">[</span><span class="n">key</span><span class="p">])</span>
</div>
<div class="viewcode-block" id="Parameters.usage"><a class="viewcode-back" href="../../TkGUI.html#scitools.TkGUI.Parameters.usage">[docs]</a>    <span class="k">def</span> <span class="nf">usage</span><span class="p">(</span><span class="bp">self</span><span class="p">):</span>
        <span class="sd">&quot;&quot;&quot;Print legal command-line options.&quot;&quot;&quot;</span>
        <span class="n">s</span> <span class="o">=</span> <span class="s">&#39;&#39;</span> <span class="c"># returned message</span>
        <span class="k">for</span> <span class="n">p</span> <span class="ow">in</span> <span class="bp">self</span><span class="o">.</span><span class="n">dict</span><span class="p">:</span>
            <span class="k">if</span> <span class="n">p</span><span class="o">.</span><span class="n">find</span><span class="p">(</span><span class="s">&#39; &#39;</span><span class="p">)</span> <span class="o">!=</span> <span class="o">-</span><span class="mi">1</span><span class="p">:</span>
                <span class="n">opt</span> <span class="o">=</span> <span class="n">p</span><span class="o">.</span><span class="n">replace</span><span class="p">(</span><span class="s">&#39; &#39;</span><span class="p">,</span> <span class="s">&#39;__&#39;</span><span class="p">)</span>
            <span class="k">else</span><span class="p">:</span>
                <span class="n">opt</span> <span class="o">=</span> <span class="n">p</span>
            <span class="k">if</span> <span class="bp">self</span><span class="o">.</span><span class="n">dict</span><span class="p">[</span><span class="n">p</span><span class="p">]</span><span class="o">.</span><span class="n">help</span> <span class="ow">is</span> <span class="ow">not</span> <span class="bp">None</span><span class="p">:</span>
                <span class="n">s</span> <span class="o">+=</span> <span class="s">&#39;--&#39;</span> <span class="o">+</span> <span class="s">&#39;</span><span class="si">%-30s</span><span class="s">&#39;</span> <span class="o">%</span> <span class="n">opt</span> <span class="o">+</span> <span class="s">&#39; &#39;</span> <span class="o">+</span> <span class="bp">self</span><span class="o">.</span><span class="n">dict</span><span class="p">[</span><span class="n">p</span><span class="p">]</span><span class="o">.</span><span class="n">help</span> <span class="o">+</span> <span class="s">&#39;</span><span class="se">\n</span><span class="s">&#39;</span>
            <span class="k">else</span><span class="p">:</span>
                <span class="n">s</span> <span class="o">+=</span> <span class="s">&#39;--&#39;</span> <span class="o">+</span> <span class="n">opt</span> <span class="o">+</span> <span class="s">&#39; value &#39;</span>

        <span class="k">return</span> <span class="n">s</span>
</div>
<div class="viewcode-block" id="Parameters.dump"><a class="viewcode-back" href="../../TkGUI.html#scitools.TkGUI.Parameters.dump">[docs]</a>    <span class="k">def</span> <span class="nf">dump</span><span class="p">(</span><span class="bp">self</span><span class="p">):</span>
        <span class="n">s</span> <span class="o">=</span> <span class="s">&#39;&#39;</span>
        <span class="k">for</span> <span class="n">p</span> <span class="ow">in</span> <span class="bp">self</span><span class="o">.</span><span class="n">dict</span><span class="p">:</span>
            <span class="n">s</span> <span class="o">+=</span> <span class="nb">repr</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">dict</span><span class="p">[</span><span class="n">p</span><span class="p">])</span> <span class="o">+</span> <span class="s">&#39;</span><span class="se">\n</span><span class="s">&#39;</span>
        <span class="k">return</span> <span class="n">s</span>
</div>
<div class="viewcode-block" id="Parameters.__str__"><a class="viewcode-back" href="../../TkGUI.html#scitools.TkGUI.Parameters.__str__">[docs]</a>    <span class="k">def</span> <span class="nf">__str__</span><span class="p">(</span><span class="bp">self</span><span class="p">):</span>
        <span class="k">return</span> <span class="nb">str</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">get</span><span class="p">())</span>
</div>
<div class="viewcode-block" id="Parameters.__repr__"><a class="viewcode-back" href="../../TkGUI.html#scitools.TkGUI.Parameters.__repr__">[docs]</a>    <span class="k">def</span> <span class="nf">__repr__</span><span class="p">(</span><span class="bp">self</span><span class="p">):</span>
        <span class="n">s</span> <span class="o">=</span> <span class="s">&#39;Parameters: interface=&quot;</span><span class="si">%s</span><span class="s">&quot;</span><span class="se">\n</span><span class="s">&#39;</span> <span class="o">%</span> <span class="bp">self</span><span class="o">.</span><span class="n">_interface</span>
        <span class="k">for</span> <span class="n">name</span> <span class="ow">in</span> <span class="bp">self</span><span class="o">.</span><span class="n">dict</span><span class="p">:</span>
            <span class="n">s</span> <span class="o">+=</span> <span class="nb">repr</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">dict</span><span class="p">[</span><span class="n">name</span><span class="p">])</span> <span class="o">+</span> <span class="s">&#39;</span><span class="se">\n</span><span class="s">&#39;</span>
        <span class="k">return</span> <span class="n">s</span>


</div></div>
<div class="viewcode-block" id="parametersGUI"><a class="viewcode-back" href="../../TkGUI.html#scitools.TkGUI.parametersGUI">[docs]</a><span class="k">def</span> <span class="nf">parametersGUI</span><span class="p">(</span><span class="n">p</span><span class="p">,</span> <span class="n">parent</span><span class="p">,</span> <span class="n">pack_side</span><span class="o">=</span><span class="s">&#39;top&#39;</span><span class="p">,</span>
                  <span class="n">scrolled</span><span class="o">=</span><span class="p">{</span><span class="s">&#39;height&#39;</span><span class="p">:</span> <span class="mi">400</span><span class="p">,</span> <span class="s">&#39;width&#39;</span><span class="p">:</span> <span class="mi">350</span><span class="p">}):</span>
    <span class="sd">&quot;&quot;&quot;</span>
<span class="sd">    Load all parameters in a Parameters object p into a GUI.</span>

<span class="sd">    parent          parent widget</span>
<span class="sd">    pack_side       packing is donw with</span>
<span class="sd">                    widget.pack(side=pack_side, expand=1, fill=&#39;both&#39;)</span>
<span class="sd">    scrolled        False: use standard Tk Frame</span>
<span class="sd">                    non-empty dict: use Pmw.ScrolledFrame with the</span>
<span class="sd">                    prescribed height and width</span>
<span class="sd">    &quot;&quot;&quot;</span>
    <span class="n">p</span><span class="o">.</span><span class="n">endadd</span><span class="p">()</span>  <span class="c"># for safety</span>
    <span class="k">if</span> <span class="n">scrolled</span><span class="p">:</span>
        <span class="n">frame</span> <span class="o">=</span> <span class="n">Pmw</span><span class="o">.</span><span class="n">ScrolledFrame</span><span class="p">(</span><span class="n">parent</span><span class="p">,</span>
          <span class="n">usehullsize</span><span class="o">=</span><span class="mi">1</span><span class="p">,</span> <span class="n">hull_width</span><span class="o">=</span><span class="n">scrolled</span><span class="p">[</span><span class="s">&#39;width&#39;</span><span class="p">],</span>
                         <span class="n">hull_height</span><span class="o">=</span><span class="n">scrolled</span><span class="p">[</span><span class="s">&#39;height&#39;</span><span class="p">])</span>
        <span class="n">frame</span><span class="o">.</span><span class="n">pack</span><span class="p">(</span><span class="n">side</span><span class="o">=</span><span class="n">pack_side</span><span class="p">,</span> <span class="n">fill</span><span class="o">=</span><span class="s">&#39;both&#39;</span><span class="p">,</span> <span class="n">expand</span><span class="o">=</span><span class="mi">1</span><span class="p">)</span>
        <span class="n">frame</span> <span class="o">=</span> <span class="n">frame</span><span class="o">.</span><span class="n">interior</span><span class="p">()</span>
    <span class="k">else</span><span class="p">:</span>
        <span class="n">frame</span> <span class="o">=</span> <span class="n">Tkinter</span><span class="o">.</span><span class="n">Frame</span><span class="p">(</span><span class="n">parent</span><span class="p">,</span> <span class="n">borderwidth</span><span class="o">=</span><span class="mi">2</span><span class="p">)</span>
        <span class="n">frame</span><span class="o">.</span><span class="n">pack</span><span class="p">(</span><span class="n">side</span><span class="o">=</span><span class="n">pack_side</span><span class="p">,</span> <span class="n">fill</span><span class="o">=</span><span class="s">&#39;both&#39;</span><span class="p">,</span> <span class="n">expand</span><span class="o">=</span><span class="mi">1</span><span class="p">)</span>

    <span class="n">widgets</span> <span class="o">=</span> <span class="p">[]</span>  <span class="c"># for alignment</span>
    <span class="k">for</span> <span class="n">obj</span> <span class="ow">in</span> <span class="n">p</span><span class="o">.</span><span class="n">parameters_sequence</span><span class="p">:</span>
        <span class="c"># must be set on beforehand: obj.widget_type = &#39;entry&#39;</span>
        <span class="k">if</span> <span class="n">obj</span><span class="o">.</span><span class="n">widget_type</span> <span class="ow">is</span> <span class="bp">None</span><span class="p">:</span>
            <span class="k">raise</span> <span class="ne">TypeError</span><span class="p">(</span><span class="s">&quot;widget_type attribute &quot;</span>\
                            <span class="s">&quot;must be set for InputPrmGUI &#39;</span><span class="si">%s</span><span class="s">&#39;&quot;</span> <span class="o">%</span> <span class="n">obj</span><span class="o">.</span><span class="n">name</span><span class="p">)</span>
        <span class="n">obj</span><span class="o">.</span><span class="n">parent</span> <span class="o">=</span> <span class="n">frame</span>
        <span class="n">obj</span><span class="o">.</span><span class="n">make_widget</span><span class="p">()</span>
        <span class="c">#obj.widget.pack(side=&#39;top&#39;, padx=5, pady=5, fill=&#39;x&#39;, expand=1)</span>
        <span class="n">obj</span><span class="o">.</span><span class="n">widget</span><span class="o">.</span><span class="n">pack</span><span class="p">(</span><span class="n">side</span><span class="o">=</span><span class="s">&#39;top&#39;</span><span class="p">,</span> <span class="n">padx</span><span class="o">=</span><span class="mi">5</span><span class="p">,</span> <span class="n">pady</span><span class="o">=</span><span class="mi">3</span><span class="p">,</span> <span class="n">anchor</span><span class="o">=</span><span class="s">&#39;w&#39;</span><span class="p">)</span>
        <span class="k">if</span> <span class="n">obj</span><span class="o">.</span><span class="n">widget_type</span> <span class="o">==</span> <span class="s">&#39;entry&#39;</span> <span class="ow">or</span> \
               <span class="n">obj</span><span class="o">.</span><span class="n">widget_type</span> <span class="o">==</span> <span class="s">&#39;option&#39;</span><span class="p">:</span>
            <span class="n">widgets</span><span class="o">.</span><span class="n">append</span><span class="p">(</span><span class="n">obj</span><span class="o">.</span><span class="n">widget</span><span class="p">)</span>
    <span class="n">Pmw</span><span class="o">.</span><span class="n">alignlabels</span><span class="p">(</span><span class="n">widgets</span><span class="p">)</span>  <span class="c"># nice alignment</span>

</div>
<div class="viewcode-block" id="AutoSimVizGUI"><a class="viewcode-back" href="../../TkGUI.html#scitools.TkGUI.AutoSimVizGUI">[docs]</a><span class="k">class</span> <span class="nc">AutoSimVizGUI</span><span class="p">:</span>
    <span class="sd">&quot;&quot;&quot;</span>
<span class="sd">    Organize a set of widgets for input data together with</span>
<span class="sd">    buttons for running a simulator and performing visualizations.</span>
<span class="sd">    The input data are represented by a Parameters object</span>
<span class="sd">    from the ParameterInterface module.</span>
<span class="sd">    The individual parameters in this object are represented as</span>
<span class="sd">    InputPrmGUI instances.</span>
<span class="sd">    The application code creates Parameters object</span>
<span class="sd">    (recall to call addend() after all parameters are registered).</span>

<span class="sd">    The method make_prmGUI takes the Parameters objects,</span>
<span class="sd">    makes the associated widgets and packs them in an appropriate</span>
<span class="sd">    GUI. All widgets may appear in one column, in the order the</span>
<span class="sd">    parameters were registered in the Parameters object, if</span>
<span class="sd">    sort_widgets is false. Otherwise, two column of widgets are</span>
<span class="sd">    made: one with sliders and one with the rest (checkbuttons,</span>
<span class="sd">    entries, options). The sequence of widgets in the latter case</span>
<span class="sd">    is determined by the sequence of registration in the Parameters,</span>
<span class="sd">    e.g., all sliders are grouped in their original sequence,</span>
<span class="sd">    all option menus are grouped in their original sequence, and so on.</span>

<span class="sd">    The method make_buttonGUI creates buttons for simulation and</span>
<span class="sd">    visualization, plus an optional logo and a help button.</span>
<span class="sd">    If more buttons are wanted, one can add these to the</span>
<span class="sd">    button_frame Tkinter.Frame attribute.</span>

<span class="sd">    There is an optional column of widgets with BLT graphs for</span>
<span class="sd">    curve plotting, enabled by the make_curveplotGUI method.</span>

<span class="sd">    The great advantage of this class is that the application code</span>
<span class="sd">    can concentrate on defining input parameters to a problem,</span>
<span class="sd">    the simulation and visualization functions, and leave it to</span>
<span class="sd">    this class to put everything together. It is then an easy task</span>
<span class="sd">    to change the layout of the whole GUI in one common place.</span>
<span class="sd">    &quot;&quot;&quot;</span>

<div class="viewcode-block" id="AutoSimVizGUI.__init__"><a class="viewcode-back" href="../../TkGUI.html#scitools.TkGUI.AutoSimVizGUI.__init__">[docs]</a>    <span class="k">def</span> <span class="nf">__init__</span><span class="p">(</span><span class="bp">self</span><span class="p">):</span>
        <span class="kn">import</span> <span class="nn">modulecheck</span>
        <span class="n">modulecheck</span><span class="o">.</span><span class="n">exception</span><span class="p">(</span><span class="s">&quot;Class AutoSimVizGUI&quot;</span><span class="p">,</span> <span class="s">&#39;Pmw&#39;</span><span class="p">,</span> <span class="s">&#39;Tkinter&#39;</span><span class="p">)</span>
        <span class="k">return</span>
</div>
<div class="viewcode-block" id="AutoSimVizGUI.make_prmGUI"><a class="viewcode-back" href="../../TkGUI.html#scitools.TkGUI.AutoSimVizGUI.make_prmGUI">[docs]</a>    <span class="k">def</span> <span class="nf">make_prmGUI</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span>
                    <span class="n">parent</span><span class="p">,</span>
                    <span class="n">parameters</span><span class="p">,</span>
                    <span class="n">sort_widgets</span><span class="o">=</span><span class="mi">0</span><span class="p">,</span>
                    <span class="n">height</span><span class="o">=</span><span class="bp">None</span><span class="p">,</span>
                    <span class="n">pane</span><span class="o">=</span><span class="mi">0</span>
                    <span class="p">):</span>
        <span class="sd">&quot;&quot;&quot;</span>
<span class="sd">        The height parameter controls the height (in pixels) of</span>
<span class="sd">        the GUI.</span>

<span class="sd">        The columns are realized by Pmw.ScrolledFrame widgets.</span>
<span class="sd">        &quot;&quot;&quot;</span>

        <span class="bp">self</span><span class="o">.</span><span class="n">p</span> <span class="o">=</span> <span class="n">parameters</span>  <span class="c"># scitools.ParameterInterface.Parameters instance</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">p</span><span class="o">.</span><span class="n">endadd</span><span class="p">()</span>

        <span class="k">if</span> <span class="n">sort_widgets</span><span class="p">:</span>
            <span class="bp">self</span><span class="o">.</span><span class="n">sliders_sequence</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">p</span><span class="o">.</span><span class="n">sliders_sequence</span>
        <span class="k">else</span><span class="p">:</span>
            <span class="bp">self</span><span class="o">.</span><span class="n">sliders_sequence</span> <span class="o">=</span> <span class="bp">None</span>
        <span class="k">if</span> <span class="n">sort_widgets</span><span class="p">:</span>
            <span class="bp">self</span><span class="o">.</span><span class="n">entries_sequence</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">p</span><span class="o">.</span><span class="n">entries_sequence</span>
        <span class="k">else</span><span class="p">:</span>
            <span class="bp">self</span><span class="o">.</span><span class="n">entries_sequence</span> <span class="o">=</span> <span class="bp">None</span>
        <span class="k">if</span> <span class="n">sort_widgets</span><span class="p">:</span>
            <span class="bp">self</span><span class="o">.</span><span class="n">options_sequence</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">p</span><span class="o">.</span><span class="n">options_sequence</span>
        <span class="k">else</span><span class="p">:</span>
            <span class="bp">self</span><span class="o">.</span><span class="n">options_sequence</span> <span class="o">=</span> <span class="bp">None</span>
        <span class="k">if</span> <span class="n">sort_widgets</span><span class="p">:</span>
            <span class="bp">self</span><span class="o">.</span><span class="n">checkbuttons_sequence</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">p</span><span class="o">.</span><span class="n">checkbt_sequence</span>
        <span class="k">else</span><span class="p">:</span>
            <span class="bp">self</span><span class="o">.</span><span class="n">checkbuttons_sequence</span> <span class="o">=</span> <span class="bp">None</span>
        <span class="k">if</span> <span class="ow">not</span> <span class="n">sort_widgets</span><span class="p">:</span>
            <span class="bp">self</span><span class="o">.</span><span class="n">parameters_sequence</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">p</span><span class="o">.</span><span class="n">parameters_sequence</span>
        <span class="k">else</span><span class="p">:</span>
            <span class="bp">self</span><span class="o">.</span><span class="n">parameters_sequence</span> <span class="o">=</span> <span class="bp">None</span>


        <span class="bp">self</span><span class="o">.</span><span class="n">master</span> <span class="o">=</span> <span class="n">parent</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">top</span> <span class="o">=</span> <span class="n">Tkinter</span><span class="o">.</span><span class="n">Frame</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">master</span><span class="p">)</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">top</span><span class="o">.</span><span class="n">pack</span><span class="p">(</span><span class="n">expand</span><span class="o">=</span><span class="mi">1</span><span class="p">,</span> <span class="n">fill</span><span class="o">=</span><span class="s">&#39;both&#39;</span><span class="p">)</span>  <span class="c"># could be moved to pack method...</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">top_columns</span> <span class="o">=</span> <span class="n">Tkinter</span><span class="o">.</span><span class="n">Frame</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">top</span><span class="p">)</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">top_columns</span><span class="o">.</span><span class="n">pack</span><span class="p">(</span><span class="n">expand</span><span class="o">=</span><span class="mi">1</span><span class="p">,</span> <span class="n">fill</span><span class="o">=</span><span class="s">&#39;both&#39;</span><span class="p">)</span>

        <span class="bp">self</span><span class="o">.</span><span class="n">pane</span> <span class="o">=</span> <span class="n">pane</span>
        <span class="k">if</span> <span class="bp">self</span><span class="o">.</span><span class="n">pane</span><span class="p">:</span>
            <span class="bp">self</span><span class="o">.</span><span class="n">top_pane</span> <span class="o">=</span> <span class="n">Pmw</span><span class="o">.</span><span class="n">PanedWidget</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">top_columns</span><span class="p">,</span>
                                            <span class="n">orient</span><span class="o">=</span><span class="s">&#39;horizontal&#39;</span><span class="p">)</span>
<span class="c">###                            hull_width=900, hull_height=600)</span>
            <span class="bp">self</span><span class="o">.</span><span class="n">top_pane</span><span class="o">.</span><span class="n">pack</span><span class="p">(</span><span class="n">expand</span><span class="o">=</span><span class="mi">1</span><span class="p">,</span> <span class="n">fill</span><span class="o">=</span><span class="s">&#39;both&#39;</span><span class="p">)</span>

        <span class="k">if</span> <span class="bp">self</span><span class="o">.</span><span class="n">sliders_sequence</span> <span class="ow">is</span> <span class="ow">not</span> <span class="bp">None</span><span class="p">:</span>
            <span class="c"># create a scrolled frame with a set of slider widgets</span>
            <span class="c"># below each other:</span>
            <span class="k">if</span> <span class="bp">self</span><span class="o">.</span><span class="n">pane</span><span class="p">:</span>
                <span class="bp">self</span><span class="o">.</span><span class="n">top_pane</span><span class="o">.</span><span class="n">add</span><span class="p">(</span><span class="s">&#39;sliders&#39;</span><span class="p">,</span> <span class="nb">min</span><span class="o">=</span><span class="mi">340</span><span class="p">)</span>
                <span class="n">parent</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">top_pane</span><span class="o">.</span><span class="n">pane</span><span class="p">(</span><span class="s">&#39;sliders&#39;</span><span class="p">)</span>
            <span class="k">else</span><span class="p">:</span>
                <span class="n">parent</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">top_columns</span>
            <span class="bp">self</span><span class="o">.</span><span class="n">sliders_frame</span> <span class="o">=</span> <span class="n">Pmw</span><span class="o">.</span><span class="n">ScrolledFrame</span><span class="p">(</span><span class="n">parent</span><span class="p">,</span>
                <span class="n">usehullsize</span><span class="o">=</span><span class="mi">1</span><span class="p">,</span> <span class="n">hull_width</span><span class="o">=</span><span class="mi">320</span><span class="p">,</span> <span class="n">hull_height</span><span class="o">=</span><span class="n">height</span><span class="p">)</span>
            <span class="bp">self</span><span class="o">.</span><span class="n">sliders_frame</span><span class="o">.</span><span class="n">pack</span><span class="p">(</span><span class="n">side</span><span class="o">=</span><span class="s">&#39;left&#39;</span><span class="p">,</span> <span class="n">fill</span><span class="o">=</span><span class="s">&#39;both&#39;</span><span class="p">,</span> <span class="n">expand</span><span class="o">=</span><span class="mi">1</span><span class="p">)</span>
            <span class="bp">self</span><span class="o">.</span><span class="n">sliders_frame</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">sliders_frame</span><span class="o">.</span><span class="n">interior</span><span class="p">()</span>

            <span class="k">for</span> <span class="n">obj</span> <span class="ow">in</span> <span class="bp">self</span><span class="o">.</span><span class="n">sliders_sequence</span><span class="p">:</span>
                <span class="k">if</span> <span class="n">obj</span><span class="o">.</span><span class="n">widget_type</span> <span class="ow">is</span> <span class="bp">None</span><span class="p">:</span>
                    <span class="n">obj</span><span class="o">.</span><span class="n">widget_type</span> <span class="o">=</span> <span class="s">&#39;slider&#39;</span>
                <span class="n">obj</span><span class="o">.</span><span class="n">parent</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">sliders_frame</span>
                <span class="n">obj</span><span class="o">.</span><span class="n">make_widget</span><span class="p">()</span>
                <span class="n">obj</span><span class="o">.</span><span class="n">widget</span><span class="o">.</span><span class="n">pack</span><span class="p">(</span><span class="n">side</span><span class="o">=</span><span class="s">&#39;top&#39;</span><span class="p">,</span> <span class="n">padx</span><span class="o">=</span><span class="mi">5</span><span class="p">,</span> <span class="n">pady</span><span class="o">=</span><span class="mi">3</span><span class="p">,</span>
                                <span class="n">fill</span><span class="o">=</span><span class="s">&#39;x&#39;</span><span class="p">,</span> <span class="n">expand</span><span class="o">=</span><span class="mi">1</span><span class="p">)</span>

        <span class="k">if</span> <span class="bp">self</span><span class="o">.</span><span class="n">entries_sequence</span> <span class="ow">is</span> <span class="ow">not</span> <span class="bp">None</span> <span class="ow">or</span> \
           <span class="bp">self</span><span class="o">.</span><span class="n">options_sequence</span> <span class="ow">is</span> <span class="ow">not</span> <span class="bp">None</span> <span class="ow">or</span> \
           <span class="bp">self</span><span class="o">.</span><span class="n">checkbuttons_sequence</span> <span class="ow">is</span> <span class="ow">not</span> <span class="bp">None</span><span class="p">:</span>
            <span class="k">if</span> <span class="bp">self</span><span class="o">.</span><span class="n">pane</span><span class="p">:</span>
                <span class="bp">self</span><span class="o">.</span><span class="n">top_pane</span><span class="o">.</span><span class="n">add</span><span class="p">(</span><span class="s">&#39;entries&#39;</span><span class="p">,</span> <span class="nb">min</span><span class="o">=</span><span class="mi">175</span><span class="p">)</span>
                <span class="n">parent</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">top_pane</span><span class="o">.</span><span class="n">pane</span><span class="p">(</span><span class="s">&#39;entries&#39;</span><span class="p">)</span>
            <span class="k">else</span><span class="p">:</span>
                <span class="n">parent</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">top_columns</span>
            <span class="bp">self</span><span class="o">.</span><span class="n">entries_frame</span> <span class="o">=</span> <span class="n">Pmw</span><span class="o">.</span><span class="n">ScrolledFrame</span><span class="p">(</span><span class="n">parent</span><span class="p">,</span>
                <span class="n">usehullsize</span><span class="o">=</span><span class="mi">1</span><span class="p">,</span> <span class="n">hull_width</span><span class="o">=</span><span class="mi">240</span><span class="p">,</span> <span class="n">hull_height</span><span class="o">=</span><span class="n">height</span><span class="p">)</span>
            <span class="bp">self</span><span class="o">.</span><span class="n">entries_frame</span><span class="o">.</span><span class="n">pack</span><span class="p">(</span><span class="n">side</span><span class="o">=</span><span class="s">&#39;left&#39;</span><span class="p">,</span> <span class="n">fill</span><span class="o">=</span><span class="s">&#39;both&#39;</span><span class="p">,</span> <span class="n">expand</span><span class="o">=</span><span class="mi">1</span><span class="p">)</span>
            <span class="bp">self</span><span class="o">.</span><span class="n">entries_frame</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">entries_frame</span><span class="o">.</span><span class="n">interior</span><span class="p">()</span>

        <span class="n">widgets</span> <span class="o">=</span> <span class="p">[]</span>
        <span class="k">if</span> <span class="bp">self</span><span class="o">.</span><span class="n">entries_sequence</span> <span class="ow">is</span> <span class="ow">not</span> <span class="bp">None</span><span class="p">:</span>
            <span class="k">for</span> <span class="n">obj</span> <span class="ow">in</span> <span class="bp">self</span><span class="o">.</span><span class="n">entries_sequence</span><span class="p">:</span>
                <span class="k">if</span> <span class="n">obj</span><span class="o">.</span><span class="n">widget_type</span> <span class="ow">is</span> <span class="bp">None</span><span class="p">:</span>
                    <span class="n">obj</span><span class="o">.</span><span class="n">widget_type</span> <span class="o">=</span> <span class="s">&#39;entry&#39;</span>
                <span class="n">obj</span><span class="o">.</span><span class="n">parent</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">entries_frame</span>
                <span class="n">obj</span><span class="o">.</span><span class="n">make_widget</span><span class="p">()</span>
                <span class="n">obj</span><span class="o">.</span><span class="n">widget</span><span class="o">.</span><span class="n">pack</span><span class="p">(</span><span class="n">side</span><span class="o">=</span><span class="s">&#39;top&#39;</span><span class="p">,</span> <span class="n">padx</span><span class="o">=</span><span class="mi">5</span><span class="p">,</span> <span class="n">pady</span><span class="o">=</span><span class="mi">3</span><span class="p">,</span>
                                <span class="n">fill</span><span class="o">=</span><span class="s">&#39;x&#39;</span><span class="p">,</span> <span class="n">expand</span><span class="o">=</span><span class="mi">1</span><span class="p">,</span> <span class="n">anchor</span><span class="o">=</span><span class="s">&#39;w&#39;</span><span class="p">)</span>
                <span class="n">widgets</span><span class="o">.</span><span class="n">append</span><span class="p">(</span><span class="n">obj</span><span class="o">.</span><span class="n">widget</span><span class="p">)</span>

        <span class="c"># add option menus under the entries in the second column:</span>
        <span class="k">if</span> <span class="bp">self</span><span class="o">.</span><span class="n">options_sequence</span> <span class="ow">is</span> <span class="ow">not</span> <span class="bp">None</span><span class="p">:</span>
            <span class="k">for</span> <span class="n">obj</span> <span class="ow">in</span> <span class="bp">self</span><span class="o">.</span><span class="n">options_sequence</span><span class="p">:</span>
                <span class="k">if</span> <span class="n">obj</span><span class="o">.</span><span class="n">widget_type</span> <span class="ow">is</span> <span class="bp">None</span><span class="p">:</span>
                    <span class="n">obj</span><span class="o">.</span><span class="n">widget_type</span> <span class="o">=</span> <span class="s">&#39;option&#39;</span>
                <span class="n">obj</span><span class="o">.</span><span class="n">parent</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">entries_frame</span>
                <span class="n">obj</span><span class="o">.</span><span class="n">make_widget</span><span class="p">()</span>
                <span class="n">obj</span><span class="o">.</span><span class="n">widget</span><span class="o">.</span><span class="n">pack</span><span class="p">(</span><span class="n">side</span><span class="o">=</span><span class="s">&#39;top&#39;</span><span class="p">,</span> <span class="n">padx</span><span class="o">=</span><span class="mi">5</span><span class="p">,</span> <span class="n">pady</span><span class="o">=</span><span class="mi">3</span><span class="p">,</span> <span class="n">anchor</span><span class="o">=</span><span class="s">&#39;w&#39;</span><span class="p">)</span>
                <span class="n">widgets</span><span class="o">.</span><span class="n">append</span><span class="p">(</span><span class="n">obj</span><span class="o">.</span><span class="n">widget</span><span class="p">)</span>
        <span class="n">Pmw</span><span class="o">.</span><span class="n">alignlabels</span><span class="p">(</span><span class="n">widgets</span><span class="p">)</span>  <span class="c"># nice alignment</span>

        <span class="c"># add checkbuttons under the options/entries in the second column:</span>
        <span class="k">if</span> <span class="bp">self</span><span class="o">.</span><span class="n">checkbuttons_sequence</span> <span class="ow">is</span> <span class="ow">not</span> <span class="bp">None</span><span class="p">:</span>
            <span class="k">for</span> <span class="n">obj</span> <span class="ow">in</span> <span class="bp">self</span><span class="o">.</span><span class="n">checkbuttons_sequence</span><span class="p">:</span>
                <span class="k">if</span> <span class="n">obj</span><span class="o">.</span><span class="n">widget_type</span> <span class="ow">is</span> <span class="bp">None</span><span class="p">:</span>
                    <span class="n">obj</span><span class="o">.</span><span class="n">widget_type</span> <span class="o">=</span> <span class="s">&#39;checkbutton&#39;</span>
                <span class="n">obj</span><span class="o">.</span><span class="n">parent</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">entries_frame</span>
                <span class="n">obj</span><span class="o">.</span><span class="n">make_widget</span><span class="p">()</span>
                <span class="n">obj</span><span class="o">.</span><span class="n">widget</span><span class="o">.</span><span class="n">pack</span><span class="p">(</span><span class="n">side</span><span class="o">=</span><span class="s">&#39;top&#39;</span><span class="p">,</span> <span class="n">padx</span><span class="o">=</span><span class="mi">5</span><span class="p">,</span> <span class="n">pady</span><span class="o">=</span><span class="mi">3</span><span class="p">,</span> <span class="n">anchor</span><span class="o">=</span><span class="s">&#39;w&#39;</span><span class="p">)</span>

        <span class="k">if</span> <span class="bp">self</span><span class="o">.</span><span class="n">parameters_sequence</span> <span class="ow">is</span> <span class="ow">not</span> <span class="bp">None</span><span class="p">:</span>
            <span class="k">if</span> <span class="bp">self</span><span class="o">.</span><span class="n">pane</span><span class="p">:</span>
                <span class="bp">self</span><span class="o">.</span><span class="n">top_pane</span><span class="o">.</span><span class="n">add</span><span class="p">(</span><span class="s">&#39;parameters&#39;</span><span class="p">,</span> <span class="nb">min</span><span class="o">=</span><span class="mi">350</span><span class="p">)</span>
                <span class="n">parent</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">top_pane</span><span class="o">.</span><span class="n">pane</span><span class="p">(</span><span class="s">&#39;parameters&#39;</span><span class="p">)</span>
            <span class="k">else</span><span class="p">:</span>
                <span class="n">parent</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">top_columns</span>

            <span class="k">if</span> <span class="n">height</span> <span class="ow">is</span> <span class="bp">None</span><span class="p">:</span>
                <span class="n">height</span> <span class="o">=</span> <span class="nb">min</span><span class="p">(</span><span class="nb">len</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">parameters_sequence</span><span class="p">)</span><span class="o">*</span><span class="mi">80</span><span class="p">,</span> <span class="mi">700</span><span class="p">)</span>

            <span class="n">parametersGUI</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">p</span><span class="p">,</span> <span class="n">parent</span><span class="p">,</span>
                         <span class="n">pack_side</span><span class="o">=</span><span class="s">&#39;left&#39;</span><span class="p">,</span>
                         <span class="n">scrolled</span><span class="o">=</span><span class="p">{</span><span class="s">&#39;height&#39;</span><span class="p">:</span><span class="n">height</span><span class="p">,</span> <span class="s">&#39;width&#39;</span><span class="p">:</span><span class="mi">350</span><span class="p">})</span>

        <span class="c"># note: if we use Pmw.ScrolledCanvas, call canvas.resizescrollregion()</span>
</div>
<div class="viewcode-block" id="AutoSimVizGUI.make_buttonGUI"><a class="viewcode-back" href="../../TkGUI.html#scitools.TkGUI.AutoSimVizGUI.make_buttonGUI">[docs]</a>    <span class="k">def</span> <span class="nf">make_buttonGUI</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">parent</span><span class="p">,</span> <span class="n">buttons</span><span class="o">=</span><span class="p">[],</span> <span class="n">logo</span><span class="o">=</span><span class="bp">None</span><span class="p">,</span> <span class="n">help</span><span class="o">=</span><span class="bp">None</span><span class="p">):</span>
        <span class="k">if</span> <span class="bp">self</span><span class="o">.</span><span class="n">pane</span><span class="p">:</span>
            <span class="c">#self.top_pane.add(&#39;buttons&#39;, min=300)</span>
            <span class="bp">self</span><span class="o">.</span><span class="n">top_pane</span><span class="o">.</span><span class="n">add</span><span class="p">(</span><span class="s">&#39;buttons&#39;</span><span class="p">)</span>
            <span class="n">parent</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">top_pane</span><span class="o">.</span><span class="n">pane</span><span class="p">(</span><span class="s">&#39;buttons&#39;</span><span class="p">)</span>
        <span class="k">else</span><span class="p">:</span>
            <span class="n">parent</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">top_columns</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">button_frame</span> <span class="o">=</span> <span class="n">Tkinter</span><span class="o">.</span><span class="n">Frame</span><span class="p">(</span><span class="n">parent</span><span class="p">)</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">button_frame</span><span class="o">.</span><span class="n">pack</span><span class="p">(</span><span class="n">side</span><span class="o">=</span><span class="s">&#39;left&#39;</span><span class="p">)</span>

        <span class="c"># put a help button first:</span>
        <span class="k">if</span> <span class="nb">type</span><span class="p">(</span><span class="n">help</span><span class="p">)</span> <span class="ow">is</span> <span class="nb">type</span><span class="p">(</span><span class="s">&quot;&quot;</span><span class="p">):</span>  <span class="c"># description given?</span>
            <span class="bp">self</span><span class="o">.</span><span class="n">description</span> <span class="o">=</span> <span class="n">help</span>
            <span class="n">Tkinter</span><span class="o">.</span><span class="n">Button</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">button_frame</span><span class="p">,</span> <span class="n">text</span><span class="o">=</span><span class="s">&quot;Help&quot;</span><span class="p">,</span> <span class="n">width</span><span class="o">=</span><span class="mi">10</span><span class="p">,</span>
               <span class="n">command</span><span class="o">=</span><span class="bp">self</span><span class="o">.</span><span class="n">_helpwindow</span><span class="p">)</span><span class="o">.</span>\
               <span class="n">pack</span><span class="p">(</span><span class="n">side</span><span class="o">=</span><span class="s">&#39;top&#39;</span><span class="p">,</span> <span class="n">padx</span><span class="o">=</span><span class="mi">5</span><span class="p">,</span> <span class="n">pady</span><span class="o">=</span><span class="mi">3</span><span class="p">,</span> <span class="n">anchor</span><span class="o">=</span><span class="s">&quot;n&quot;</span><span class="p">)</span>


        <span class="k">if</span> <span class="n">logo</span> <span class="ow">is</span> <span class="ow">not</span> <span class="bp">None</span><span class="p">:</span>
            <span class="bp">self</span><span class="o">.</span><span class="n">logo</span> <span class="o">=</span> <span class="n">Tkinter</span><span class="o">.</span><span class="n">PhotoImage</span><span class="p">(</span><span class="nb">file</span><span class="o">=</span><span class="n">logo</span><span class="p">)</span>
            <span class="n">Tkinter</span><span class="o">.</span><span class="n">Label</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">button_frame</span><span class="p">,</span> <span class="n">image</span><span class="o">=</span><span class="bp">self</span><span class="o">.</span><span class="n">logo</span><span class="p">)</span><span class="o">.</span>\
                         <span class="n">pack</span><span class="p">(</span><span class="n">side</span><span class="o">=</span><span class="s">&#39;top&#39;</span><span class="p">,</span> <span class="n">pady</span><span class="o">=</span><span class="mi">20</span><span class="p">)</span>

        <span class="k">if</span> <span class="n">buttons</span><span class="p">:</span>
            <span class="k">for</span> <span class="n">button_name</span><span class="p">,</span> <span class="n">func</span> <span class="ow">in</span> <span class="n">buttons</span><span class="p">:</span>
                <span class="n">width</span> <span class="o">=</span> <span class="nb">max</span><span class="p">(</span><span class="nb">len</span><span class="p">(</span><span class="n">button_name</span><span class="p">),</span> <span class="mi">10</span><span class="p">)</span>
                <span class="n">Tkinter</span><span class="o">.</span><span class="n">Button</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">button_frame</span><span class="p">,</span> <span class="n">text</span><span class="o">=</span><span class="n">button_name</span><span class="p">,</span>
                           <span class="n">width</span><span class="o">=</span><span class="n">width</span><span class="p">,</span> <span class="n">command</span><span class="o">=</span><span class="n">func</span><span class="p">)</span><span class="o">.</span>\
                           <span class="n">pack</span><span class="p">(</span><span class="n">side</span><span class="o">=</span><span class="s">&#39;top&#39;</span><span class="p">,</span> <span class="n">padx</span><span class="o">=</span><span class="mi">5</span><span class="p">,</span> <span class="n">pady</span><span class="o">=</span><span class="mi">3</span><span class="p">)</span>

        <span class="bp">self</span><span class="o">.</span><span class="n">master</span><span class="o">.</span><span class="n">bind</span><span class="p">(</span><span class="s">&#39;&lt;q&gt;&#39;</span><span class="p">,</span> <span class="bp">self</span><span class="o">.</span><span class="n">_quit</span><span class="p">)</span>
        <span class="k">if</span> <span class="bp">self</span><span class="o">.</span><span class="n">pane</span><span class="p">:</span>
            <span class="bp">self</span><span class="o">.</span><span class="n">top_pane</span><span class="o">.</span><span class="n">setnaturalsize</span><span class="p">()</span>
</div>
<div class="viewcode-block" id="AutoSimVizGUI.make_curveplotGUI"><a class="viewcode-back" href="../../TkGUI.html#scitools.TkGUI.AutoSimVizGUI.make_curveplotGUI">[docs]</a>    <span class="k">def</span> <span class="nf">make_curveplotGUI</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span>
                          <span class="n">parent</span><span class="p">,</span>
                          <span class="n">no_of_plotframes</span><span class="o">=</span><span class="mi">1</span><span class="p">,</span>
                          <span class="n">placement</span><span class="o">=</span><span class="s">&#39;right&#39;</span><span class="p">,</span>
                          <span class="p">):</span>
        <span class="sd">&quot;&quot;&quot;</span>
<span class="sd">        @param parent: parent (master) widget</span>
<span class="sd">        @param no_of_plotframes: no of graph areas</span>
<span class="sd">        @param placement: placement of the plot area (&#39;right&#39; or &#39;bottom&#39;)</span>

<span class="sd">        Example on creating</span>
<span class="sd">        three plot areas to the right in the window::</span>

<span class="sd">          self.plot1, self.plot2, self.plot3 = \</span>
<span class="sd">              self.someGUI.make_curveplotGUI(parent, 3, &#39;right&#39;)</span>
<span class="sd">          self.plot1 etc. holds Pmw.Blt.Graph widgets.</span>

<span class="sd">        Create a single plot area::</span>
<span class="sd">          self.plot1 = self.someGUI.make_curveplotGUI(parent,</span>
<span class="sd">                                                      1, &#39;bottom&#39;)</span>
<span class="sd">        &quot;&quot;&quot;</span>
        <span class="k">if</span> <span class="n">placement</span> <span class="o">==</span> <span class="s">&#39;right&#39;</span><span class="p">:</span>
            <span class="k">if</span> <span class="bp">self</span><span class="o">.</span><span class="n">pane</span><span class="p">:</span>
                <span class="bp">self</span><span class="o">.</span><span class="n">top_pane</span><span class="o">.</span><span class="n">add</span><span class="p">(</span><span class="s">&#39;plot&#39;</span><span class="p">,</span> <span class="n">size</span><span class="o">=</span><span class="mi">300</span><span class="p">)</span>
                <span class="n">parent</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">top_pane</span><span class="o">.</span><span class="n">pane</span><span class="p">(</span><span class="s">&#39;plot&#39;</span><span class="p">)</span>
            <span class="k">else</span><span class="p">:</span>
                <span class="n">parent</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">top_columns</span>
            <span class="bp">self</span><span class="o">.</span><span class="n">plotframe</span> <span class="o">=</span> <span class="n">Tkinter</span><span class="o">.</span><span class="n">Frame</span><span class="p">(</span><span class="n">parent</span><span class="p">)</span>
            <span class="bp">self</span><span class="o">.</span><span class="n">plotframe</span><span class="o">.</span><span class="n">pack</span><span class="p">(</span><span class="n">side</span><span class="o">=</span><span class="s">&#39;left&#39;</span><span class="p">,</span> <span class="n">expand</span><span class="o">=</span><span class="mi">1</span><span class="p">,</span> <span class="n">fill</span><span class="o">=</span><span class="s">&#39;both&#39;</span><span class="p">)</span>
            <span class="c"># size of plot canvas:</span>
            <span class="n">width</span><span class="o">=</span><span class="mi">400</span><span class="p">;</span> <span class="n">total_height</span><span class="o">=</span><span class="mi">500</span>
        <span class="k">elif</span> <span class="n">placement</span> <span class="o">==</span> <span class="s">&#39;bottom&#39;</span><span class="p">:</span>
            <span class="bp">self</span><span class="o">.</span><span class="n">plotframe</span> <span class="o">=</span> <span class="n">Tkinter</span><span class="o">.</span><span class="n">Frame</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">top</span><span class="p">)</span>
            <span class="bp">self</span><span class="o">.</span><span class="n">plotframe</span><span class="o">.</span><span class="n">pack</span><span class="p">(</span><span class="n">side</span><span class="o">=</span><span class="s">&#39;bottom&#39;</span><span class="p">,</span> <span class="n">expand</span><span class="o">=</span><span class="mi">1</span><span class="p">,</span> <span class="n">fill</span><span class="o">=</span><span class="s">&#39;both&#39;</span><span class="p">)</span>
            <span class="c"># size of plot canvas:</span>
            <span class="n">width</span><span class="o">=</span><span class="bp">None</span><span class="p">;</span> <span class="n">total_height</span><span class="o">=</span><span class="n">no_of_plotframes</span><span class="o">*</span><span class="mi">200</span>

        <span class="n">height</span><span class="o">=</span><span class="nb">int</span><span class="p">(</span><span class="n">total_height</span><span class="o">/</span><span class="nb">float</span><span class="p">(</span><span class="n">no_of_plotframes</span><span class="p">))</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">g</span> <span class="o">=</span> <span class="p">[]</span>
        <span class="k">for</span> <span class="n">i</span> <span class="ow">in</span> <span class="nb">range</span><span class="p">(</span><span class="n">no_of_plotframes</span><span class="p">):</span>
            <span class="k">try</span><span class="p">:</span>
                <span class="bp">self</span><span class="o">.</span><span class="n">g</span><span class="o">.</span><span class="n">append</span><span class="p">(</span><span class="n">Pmw</span><span class="o">.</span><span class="n">Blt</span><span class="o">.</span><span class="n">Graph</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">plotframe</span><span class="p">,</span>
                                            <span class="n">width</span><span class="o">=</span><span class="n">width</span><span class="p">,</span><span class="n">height</span><span class="o">=</span><span class="n">height</span><span class="p">))</span>
            <span class="k">except</span><span class="p">:</span>
                <span class="k">print</span> <span class="s">&quot;Python is not linked with Blt&quot;</span><span class="p">;</span> <span class="n">sys</span><span class="o">.</span><span class="n">exit</span><span class="p">(</span><span class="mi">1</span><span class="p">)</span>
            <span class="c"># place the plot areas below each other:</span>
            <span class="bp">self</span><span class="o">.</span><span class="n">g</span><span class="p">[</span><span class="n">i</span><span class="p">]</span><span class="o">.</span><span class="n">pack</span><span class="p">(</span><span class="n">side</span><span class="o">=</span><span class="s">&#39;top&#39;</span><span class="p">,</span><span class="n">expand</span><span class="o">=</span><span class="mi">1</span><span class="p">,</span> <span class="n">fill</span><span class="o">=</span><span class="s">&#39;both&#39;</span><span class="p">)</span>

        <span class="c"># some dictionaries with self.g[i] as keys:</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">data</span> <span class="o">=</span> <span class="p">{}</span>  <span class="c"># holds (x,y) Blt vectors in a graph</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">identifier</span> <span class="o">=</span> <span class="p">{}</span> <span class="c"># holds curve identifiers (numbers) for each graph</span>
        <span class="k">for</span> <span class="n">graph</span> <span class="ow">in</span> <span class="bp">self</span><span class="o">.</span><span class="n">g</span><span class="p">:</span>
            <span class="bp">self</span><span class="o">.</span><span class="n">identifier</span><span class="p">[</span><span class="n">graph</span><span class="p">]</span> <span class="o">=</span> <span class="mi">0</span>
        <span class="c"># when a new curve is drawn, the self.nsavecurves old ones</span>
        <span class="c"># are still present</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">nsavecurves</span> <span class="o">=</span> <span class="mi">2</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">curvecolors</span> <span class="o">=</span> <span class="p">(</span><span class="s">&#39;red&#39;</span><span class="p">,</span> <span class="s">&#39;blue&#39;</span><span class="p">,</span> <span class="s">&#39;green&#39;</span><span class="p">,</span> <span class="s">&#39;yellow&#39;</span><span class="p">,</span> <span class="s">&#39;black&#39;</span><span class="p">)</span>

        <span class="k">if</span> <span class="bp">self</span><span class="o">.</span><span class="n">pane</span><span class="p">:</span>
            <span class="bp">self</span><span class="o">.</span><span class="n">top_pane</span><span class="o">.</span><span class="n">setnaturalsize</span><span class="p">()</span>

        <span class="k">return</span> <span class="bp">self</span><span class="o">.</span><span class="n">g</span>
</div>
<div class="viewcode-block" id="AutoSimVizGUI.load_curveplot"><a class="viewcode-back" href="../../TkGUI.html#scitools.TkGUI.AutoSimVizGUI.load_curveplot">[docs]</a>    <span class="k">def</span> <span class="nf">load_curveplot</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">filename</span><span class="p">,</span> <span class="n">graph</span><span class="p">,</span> <span class="n">curvename</span><span class="o">=</span><span class="s">&#39;&#39;</span><span class="p">):</span>
        <span class="sd">&quot;&quot;&quot;</span>
<span class="sd">        Load data from a two-column file into x and y Blt vectors.</span>
<span class="sd">        graph is a Pmw.Blt.Graph widget, normally returned from</span>
<span class="sd">        make_curveplotGUI.</span>

<span class="sd">        x, y = self.someGUI.load_curveplot(&#39;my.dat&#39;, self.plot2,</span>
<span class="sd">                                        curvename=&#39;measured data&#39;)</span>

<span class="sd">        One can convert x and y, which are plain Python lists, to</span>
<span class="sd">        NumPy arrays for further processing if desired.</span>
<span class="sd">        &quot;&quot;&quot;</span>
        <span class="k">if</span> <span class="nb">isinstance</span><span class="p">(</span><span class="n">graph</span><span class="p">,</span> <span class="p">(</span><span class="nb">list</span><span class="p">,</span><span class="nb">tuple</span><span class="p">)):</span>
            <span class="k">if</span> <span class="nb">len</span><span class="p">(</span><span class="n">graph</span><span class="p">)</span> <span class="o">!=</span> <span class="mi">1</span><span class="p">:</span>
                <span class="k">raise</span> <span class="ne">TypeError</span><span class="p">(</span>
                    <span class="s">&#39;graph argument is a list of length </span><span class="si">%d</span><span class="s">&gt;1, should be scalar&#39;</span> <span class="o">%</span>\
                    <span class="nb">len</span><span class="p">(</span><span class="n">graph</span><span class="p">))</span>
            <span class="k">else</span><span class="p">:</span>
                <span class="n">graph</span> <span class="o">=</span> <span class="n">graph</span><span class="p">[</span><span class="mi">0</span><span class="p">]</span>

        <span class="n">f</span> <span class="o">=</span> <span class="nb">open</span><span class="p">(</span><span class="n">filename</span><span class="p">,</span> <span class="s">&#39;r&#39;</span><span class="p">)</span>

        <span class="bp">self</span><span class="o">.</span><span class="n">identifier</span><span class="p">[</span><span class="n">graph</span><span class="p">]</span> <span class="o">+=</span> <span class="mi">1</span>  <span class="c"># identifiers are integers</span>
        <span class="nb">id</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">identifier</span><span class="p">[</span><span class="n">graph</span><span class="p">]</span>
        <span class="c"># current storage index in an array [0,..,self.nsavecurves+1]</span>
        <span class="n">counter</span> <span class="o">=</span> <span class="nb">id</span> <span class="o">%</span> <span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">nsavecurves</span><span class="o">+</span><span class="mi">1</span><span class="p">)</span>

        <span class="c"># The Blt vectors cannot be local variables, because the plot</span>
        <span class="c"># disappears when the vectors go out of scope.</span>
        <span class="c"># Letting the user handle these objects results in more user</span>
        <span class="c"># code. On the other hand, we do not know how many vectors</span>
        <span class="c"># we need. Remedy: use a dict. with graph as key and</span>
        <span class="c"># one (x,y) pair of Blt vectors</span>
        <span class="k">if</span> <span class="n">graph</span> <span class="ow">not</span> <span class="ow">in</span> <span class="bp">self</span><span class="o">.</span><span class="n">data</span><span class="p">:</span>
            <span class="bp">self</span><span class="o">.</span><span class="n">data</span><span class="p">[</span><span class="n">graph</span><span class="p">]</span> <span class="o">=</span> <span class="p">{}</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">data</span><span class="p">[</span><span class="n">graph</span><span class="p">][</span><span class="n">counter</span><span class="p">]</span> <span class="o">=</span> <span class="p">{}</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">data</span><span class="p">[</span><span class="n">graph</span><span class="p">][</span><span class="n">counter</span><span class="p">][</span><span class="s">&#39;x&#39;</span><span class="p">]</span> <span class="o">=</span> <span class="n">Pmw</span><span class="o">.</span><span class="n">Blt</span><span class="o">.</span><span class="n">Vector</span><span class="p">()</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">data</span><span class="p">[</span><span class="n">graph</span><span class="p">][</span><span class="n">counter</span><span class="p">][</span><span class="s">&#39;y&#39;</span><span class="p">]</span> <span class="o">=</span> <span class="n">Pmw</span><span class="o">.</span><span class="n">Blt</span><span class="o">.</span><span class="n">Vector</span><span class="p">()</span>
        <span class="k">for</span> <span class="n">line</span> <span class="ow">in</span> <span class="n">f</span><span class="p">:</span>
            <span class="n">numbers</span> <span class="o">=</span> <span class="n">line</span><span class="o">.</span><span class="n">split</span><span class="p">()</span>
            <span class="bp">self</span><span class="o">.</span><span class="n">data</span><span class="p">[</span><span class="n">graph</span><span class="p">][</span><span class="n">counter</span><span class="p">][</span><span class="s">&#39;x&#39;</span><span class="p">]</span><span class="o">.</span><span class="n">append</span><span class="p">(</span><span class="nb">float</span><span class="p">(</span><span class="n">numbers</span><span class="p">[</span><span class="mi">0</span><span class="p">]))</span>
            <span class="bp">self</span><span class="o">.</span><span class="n">data</span><span class="p">[</span><span class="n">graph</span><span class="p">][</span><span class="n">counter</span><span class="p">][</span><span class="s">&#39;y&#39;</span><span class="p">]</span><span class="o">.</span><span class="n">append</span><span class="p">(</span><span class="nb">float</span><span class="p">(</span><span class="n">numbers</span><span class="p">[</span><span class="mi">1</span><span class="p">]))</span>
        <span class="n">f</span><span class="o">.</span><span class="n">close</span><span class="p">()</span>

        <span class="c"># remove an old curve (save the last self.nsavecurves curves):</span>
        <span class="n">id_old</span> <span class="o">=</span> <span class="nb">id</span> <span class="o">-</span> <span class="bp">self</span><span class="o">.</span><span class="n">nsavecurves</span> <span class="o">-</span> <span class="mi">1</span>
        <span class="k">if</span> <span class="n">graph</span><span class="o">.</span><span class="n">element_exists</span><span class="p">(</span><span class="nb">str</span><span class="p">(</span><span class="n">id_old</span><span class="p">)):</span>
            <span class="n">graph</span><span class="o">.</span><span class="n">element_delete</span><span class="p">(</span><span class="nb">str</span><span class="p">(</span><span class="n">id_old</span><span class="p">))</span>  <span class="c"># remove old curve</span>
        <span class="c"># dash the old remaining curves:</span>
        <span class="k">for</span> <span class="n">i</span> <span class="ow">in</span> <span class="nb">range</span><span class="p">(</span><span class="nb">max</span><span class="p">(</span><span class="n">id_old</span><span class="o">+</span><span class="mi">1</span><span class="p">,</span><span class="mi">1</span><span class="p">),</span><span class="nb">id</span><span class="p">):</span>
            <span class="n">graph</span><span class="o">.</span><span class="n">element_configure</span><span class="p">(</span><span class="nb">str</span><span class="p">(</span><span class="n">i</span><span class="p">),</span> <span class="n">linewidth</span><span class="o">=</span><span class="mi">1</span><span class="p">)</span>
        <span class="n">color</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">curvecolors</span><span class="p">[</span><span class="n">counter</span><span class="p">]</span>

        <span class="n">graph</span><span class="o">.</span><span class="n">line_create</span><span class="p">(</span><span class="nb">str</span><span class="p">(</span><span class="nb">id</span><span class="p">),</span>
                          <span class="n">label</span><span class="o">=</span><span class="s">&#39;&#39;</span><span class="p">,</span>
                          <span class="n">xdata</span><span class="o">=</span><span class="bp">self</span><span class="o">.</span><span class="n">data</span><span class="p">[</span><span class="n">graph</span><span class="p">][</span><span class="n">counter</span><span class="p">][</span><span class="s">&#39;x&#39;</span><span class="p">],</span>
                          <span class="n">ydata</span><span class="o">=</span><span class="bp">self</span><span class="o">.</span><span class="n">data</span><span class="p">[</span><span class="n">graph</span><span class="p">][</span><span class="n">counter</span><span class="p">][</span><span class="s">&#39;y&#39;</span><span class="p">],</span>
                          <span class="n">linewidth</span><span class="o">=</span><span class="mi">2</span><span class="p">,</span> <span class="n">dashes</span><span class="o">=</span><span class="s">&#39;&#39;</span><span class="p">,</span> <span class="n">symbol</span><span class="o">=</span><span class="s">&#39;&#39;</span><span class="p">,</span>
                          <span class="n">color</span><span class="o">=</span><span class="n">color</span><span class="p">)</span>
        <span class="c"># drop label, use title instead</span>
        <span class="n">graph</span><span class="o">.</span><span class="n">configure</span><span class="p">(</span><span class="n">title</span><span class="o">=</span><span class="n">curvename</span><span class="p">)</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">master</span><span class="o">.</span><span class="n">update</span><span class="p">()</span>
        <span class="k">return</span> <span class="bp">self</span><span class="o">.</span><span class="n">data</span><span class="p">[</span><span class="n">graph</span><span class="p">][</span><span class="n">counter</span><span class="p">][</span><span class="s">&#39;x&#39;</span><span class="p">],</span>\
               <span class="bp">self</span><span class="o">.</span><span class="n">data</span><span class="p">[</span><span class="n">graph</span><span class="p">][</span><span class="n">counter</span><span class="p">][</span><span class="s">&#39;y&#39;</span><span class="p">]</span>
</div>
<div class="viewcode-block" id="AutoSimVizGUI.update_curveplot"><a class="viewcode-back" href="../../TkGUI.html#scitools.TkGUI.AutoSimVizGUI.update_curveplot">[docs]</a>    <span class="k">def</span> <span class="nf">update_curveplot</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">filename</span><span class="p">,</span> <span class="n">graph</span><span class="p">):</span>
        <span class="sd">&quot;&quot;&quot;Update Blt vectors with data from a two-column file.&quot;&quot;&quot;</span>

        <span class="nb">id</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">identifier</span><span class="p">[</span><span class="n">graph</span><span class="p">]</span>
        <span class="n">counter</span> <span class="o">=</span> <span class="nb">id</span> <span class="o">%</span> <span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">nsavecurves</span><span class="o">+</span><span class="mi">1</span><span class="p">)</span>

        <span class="n">f</span> <span class="o">=</span> <span class="nb">open</span><span class="p">(</span><span class="n">filename</span><span class="p">,</span> <span class="s">&#39;r&#39;</span><span class="p">)</span>
        <span class="n">lines</span> <span class="o">=</span> <span class="n">f</span><span class="o">.</span><span class="n">readlines</span><span class="p">()</span>
        <span class="k">if</span> <span class="nb">len</span><span class="p">(</span><span class="n">lines</span><span class="p">)</span> <span class="o">!=</span> <span class="nb">len</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">data</span><span class="p">[</span><span class="n">graph</span><span class="p">][</span><span class="n">counter</span><span class="p">][</span><span class="s">&#39;x&#39;</span><span class="p">]):</span>
            <span class="k">print</span> <span class="s">&quot;Blt vector has length=</span><span class="si">%d</span><span class="s">, but </span><span class="si">%s</span><span class="s"> has </span><span class="si">%d</span><span class="s"> lines&quot;</span> <span class="o">%</span> \
                  <span class="p">(</span><span class="nb">len</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">data</span><span class="p">[</span><span class="n">graph</span><span class="p">][</span><span class="n">counter</span><span class="p">][</span><span class="s">&#39;x&#39;</span><span class="p">]),</span><span class="nb">len</span><span class="p">(</span><span class="n">lines</span><span class="p">))</span>
        <span class="k">for</span> <span class="n">i</span> <span class="ow">in</span> <span class="nb">range</span><span class="p">(</span><span class="nb">len</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">data</span><span class="p">[</span><span class="n">graph</span><span class="p">][</span><span class="n">counter</span><span class="p">][</span><span class="s">&#39;x&#39;</span><span class="p">])):</span>
            <span class="bp">self</span><span class="o">.</span><span class="n">data</span><span class="p">[</span><span class="n">graph</span><span class="p">][</span><span class="n">counter</span><span class="p">][</span><span class="s">&#39;x&#39;</span><span class="p">][</span><span class="n">i</span><span class="p">],</span> \
            <span class="bp">self</span><span class="o">.</span><span class="n">data</span><span class="p">[</span><span class="n">graph</span><span class="p">][</span><span class="n">counter</span><span class="p">][</span><span class="s">&#39;y&#39;</span><span class="p">][</span><span class="n">i</span><span class="p">]</span> <span class="o">=</span> \
                                      <span class="nb">map</span><span class="p">(</span><span class="nb">float</span><span class="p">,</span> <span class="n">lines</span><span class="p">[</span><span class="n">i</span><span class="p">]</span><span class="o">.</span><span class="n">split</span><span class="p">())</span>
        <span class="n">f</span><span class="o">.</span><span class="n">close</span><span class="p">()</span>
</div>
    <span class="k">def</span> <span class="nf">_quit</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">event</span><span class="o">=</span><span class="bp">None</span><span class="p">):</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">master</span><span class="o">.</span><span class="n">destroy</span><span class="p">()</span>

    <span class="k">def</span> <span class="nf">_helpwindow</span><span class="p">(</span><span class="bp">self</span><span class="p">):</span>
        <span class="sd">&quot;&quot;&quot;</span>
<span class="sd">        Launch a separate toplevel window with a scrolled text widget</span>
<span class="sd">        containing self.description.</span>
<span class="sd">        &quot;&quot;&quot;</span>
        <span class="c"># read file into a text widget in a _separate_ window:</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">filewindow</span> <span class="o">=</span> <span class="n">Tkinter</span><span class="o">.</span><span class="n">Toplevel</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">master</span><span class="p">)</span> <span class="c"># new window</span>

        <span class="n">lines</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">description</span><span class="o">.</span><span class="n">split</span><span class="p">(</span><span class="s">&#39;</span><span class="se">\n</span><span class="s">&#39;</span><span class="p">)</span>
        <span class="n">nlines</span> <span class="o">=</span> <span class="nb">min</span><span class="p">(</span><span class="nb">len</span><span class="p">(</span><span class="n">lines</span><span class="p">),</span><span class="mi">30</span><span class="p">)</span>
        <span class="n">width</span> <span class="o">=</span> <span class="nb">min</span><span class="p">(</span><span class="nb">max</span><span class="p">([</span><span class="nb">len</span><span class="p">(</span><span class="n">i</span><span class="p">)</span> <span class="k">for</span> <span class="n">i</span> <span class="ow">in</span> <span class="n">lines</span><span class="p">]),</span> <span class="mi">70</span><span class="p">)</span> <span class="c"># max line width</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">filetext</span> <span class="o">=</span> <span class="n">Pmw</span><span class="o">.</span><span class="n">ScrolledText</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">filewindow</span><span class="p">,</span>
             <span class="n">borderframe</span><span class="o">=</span><span class="mi">5</span><span class="p">,</span> <span class="c"># a bit space around the text</span>
             <span class="n">vscrollmode</span><span class="o">=</span><span class="s">&#39;dynamic&#39;</span><span class="p">,</span> <span class="n">hscrollmode</span><span class="o">=</span><span class="s">&#39;dynamic&#39;</span><span class="p">,</span>
             <span class="n">labelpos</span><span class="o">=</span><span class="s">&#39;n&#39;</span><span class="p">,</span> <span class="n">label_text</span><span class="o">=</span><span class="s">&quot;Description&quot;</span><span class="p">,</span>
             <span class="n">text_width</span><span class="o">=</span><span class="n">width</span><span class="p">,</span> <span class="n">text_height</span><span class="o">=</span><span class="n">nlines</span><span class="p">,</span>
             <span class="n">text_wrap</span><span class="o">=</span><span class="s">&#39;none&#39;</span><span class="p">)</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">filetext</span><span class="o">.</span><span class="n">pack</span><span class="p">()</span>

        <span class="bp">self</span><span class="o">.</span><span class="n">filetext</span><span class="o">.</span><span class="n">insert</span><span class="p">(</span><span class="s">&#39;end&#39;</span><span class="p">,</span> <span class="bp">self</span><span class="o">.</span><span class="n">description</span><span class="p">)</span>

        <span class="c"># add a quit button:</span>
        <span class="n">Tkinter</span><span class="o">.</span><span class="n">Button</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">filewindow</span><span class="p">,</span> <span class="n">text</span><span class="o">=</span><span class="s">&quot;Quit&quot;</span><span class="p">,</span>
               <span class="n">command</span><span class="o">=</span><span class="bp">self</span><span class="o">.</span><span class="n">filewindow</span><span class="o">.</span><span class="n">destroy</span><span class="p">)</span><span class="o">.</span><span class="n">pack</span><span class="p">(</span><span class="n">pady</span><span class="o">=</span><span class="mi">10</span><span class="p">)</span>

</div>
<div class="viewcode-block" id="AutoSimVizCGI"><a class="viewcode-back" href="../../TkGUI.html#scitools.TkGUI.AutoSimVizCGI">[docs]</a><span class="k">class</span> <span class="nc">AutoSimVizCGI</span><span class="p">:</span>
    <span class="sd">&quot;&quot;&quot;</span>
<span class="sd">    Organize a set of form variables for input data.</span>
<span class="sd">    &quot;&quot;&quot;</span>

<div class="viewcode-block" id="AutoSimVizCGI.__init__"><a class="viewcode-back" href="../../TkGUI.html#scitools.TkGUI.AutoSimVizCGI.__init__">[docs]</a>    <span class="k">def</span> <span class="nf">__init__</span><span class="p">(</span><span class="bp">self</span><span class="p">):</span>
        <span class="k">return</span>
</div>
<div class="viewcode-block" id="AutoSimVizCGI.make"><a class="viewcode-back" href="../../TkGUI.html#scitools.TkGUI.AutoSimVizCGI.make">[docs]</a>    <span class="k">def</span> <span class="nf">make</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span>
             <span class="n">form</span><span class="p">,</span>
             <span class="n">parameters</span><span class="p">,</span>
             <span class="n">CGI_script</span><span class="p">,</span>
             <span class="n">imagefile</span><span class="o">=</span><span class="bp">None</span><span class="p">,</span>
             <span class="p">):</span>
        <span class="sd">&quot;&quot;&quot;</span>
<span class="sd">        Create an HTML page consisting of an optional</span>
<span class="sd">        image (specified by imagefile), a table of form variables</span>
<span class="sd">        (specified by parameters (scitools.ParameterInterface.Parameters)),</span>
<span class="sd">        and a &quot;simulate and visualize&quot; button.</span>
<span class="sd">        The resulting visualization part must be created after</span>
<span class="sd">        calling this function. Finally, the HTML page needs</span>
<span class="sd">        a footer (see the footer function).</span>
<span class="sd">        &quot;&quot;&quot;</span>

        <span class="bp">self</span><span class="o">.</span><span class="n">p</span> <span class="o">=</span> <span class="n">parameters</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">p</span><span class="o">.</span><span class="n">endadd</span><span class="p">()</span>

        <span class="n">s</span> <span class="o">=</span> <span class="s">&quot;&quot;&quot;</span>
<span class="s">&lt;html&gt;&lt;body bgcolor=&quot;white&quot;&gt;</span>
<span class="s">&quot;&quot;&quot;</span>
        <span class="k">if</span> <span class="n">imagefile</span> <span class="ow">is</span> <span class="ow">not</span> <span class="bp">None</span><span class="p">:</span>
            <span class="n">s</span> <span class="o">+=</span> <span class="s">&quot;&quot;&quot;&lt;img src=&quot;</span><span class="si">%s</span><span class="s">&quot; align=&quot;right&quot;&gt;&lt;p&gt;&quot;&quot;&quot;</span> <span class="o">%</span> <span class="n">imagefile</span>
        <span class="n">s</span> <span class="o">+=</span> <span class="s">&quot;&quot;&quot;</span>
<span class="s">&lt;form action=&quot;</span><span class="si">%s</span><span class="s">&quot; method=&quot;post&quot;&gt;</span>
<span class="s">&lt;table&gt;</span>
<span class="s">&quot;&quot;&quot;</span> <span class="o">%</span> <span class="n">CGI_script</span>
        <span class="c"># should we have a help and/or dimension column?</span>
        <span class="n">help</span> <span class="o">=</span> <span class="mi">0</span><span class="p">;</span> <span class="n">unit</span> <span class="o">=</span> <span class="mi">0</span>
        <span class="k">for</span> <span class="n">p</span> <span class="ow">in</span> <span class="bp">self</span><span class="o">.</span><span class="n">p</span><span class="o">.</span><span class="n">parameters_sequence</span><span class="p">:</span>
            <span class="k">if</span> <span class="n">p</span><span class="o">.</span><span class="n">unit</span> <span class="ow">is</span> <span class="ow">not</span> <span class="bp">None</span><span class="p">:</span> <span class="n">unit</span> <span class="o">=</span> <span class="mi">1</span>
            <span class="k">if</span> <span class="n">p</span><span class="o">.</span><span class="n">help</span> <span class="ow">is</span> <span class="ow">not</span> <span class="bp">None</span><span class="p">:</span> <span class="n">help</span> <span class="o">=</span> <span class="mi">1</span>
        <span class="k">for</span> <span class="n">p</span> <span class="ow">in</span> <span class="bp">self</span><span class="o">.</span><span class="n">p</span><span class="o">.</span><span class="n">parameters_sequence</span><span class="p">:</span>
            <span class="n">s</span> <span class="o">+=</span> <span class="s">&#39;&lt;tr&gt;</span><span class="se">\n</span><span class="s">&lt;td&gt;</span><span class="si">%s</span><span class="s">&lt;/td&gt;&lt;td&gt;</span><span class="si">%s</span><span class="s">&lt;/td&gt;&#39;</span> <span class="o">%</span> \
                 <span class="p">(</span><span class="n">p</span><span class="o">.</span><span class="n">name</span><span class="p">,</span> <span class="n">p</span><span class="o">.</span><span class="n">make_form_entry</span><span class="p">())</span>
            <span class="k">if</span> <span class="n">unit</span><span class="p">:</span>
                <span class="k">if</span> <span class="n">p</span><span class="o">.</span><span class="n">unit</span> <span class="ow">is</span> <span class="ow">not</span> <span class="bp">None</span><span class="p">:</span>
                    <span class="n">s</span> <span class="o">+=</span> <span class="s">&#39;&lt;td&gt;</span><span class="si">%s</span><span class="s">&lt;/td&gt;&#39;</span> <span class="o">%</span> <span class="n">p</span><span class="o">.</span><span class="n">unit</span>
                <span class="k">else</span><span class="p">:</span>
                    <span class="n">s</span> <span class="o">+=</span> <span class="s">&#39;&lt;td&gt;&lt;/td&gt;&#39;</span>  <span class="c"># empty</span>
            <span class="k">if</span> <span class="n">help</span><span class="p">:</span>
                <span class="k">if</span> <span class="n">p</span><span class="o">.</span><span class="n">help</span> <span class="ow">is</span> <span class="ow">not</span> <span class="bp">None</span><span class="p">:</span>
                    <span class="n">s</span> <span class="o">+=</span> <span class="s">&#39;&lt;td&gt;(</span><span class="si">%s</span><span class="s">)&lt;/td&gt;&#39;</span> <span class="o">%</span> <span class="n">p</span><span class="o">.</span><span class="n">help</span>
                <span class="k">else</span><span class="p">:</span>
                    <span class="n">s</span> <span class="o">+=</span> <span class="s">&#39;&lt;td&gt;&lt;/td&gt;&#39;</span>  <span class="c"># empty</span>

            <span class="n">s</span> <span class="o">+=</span> <span class="s">&#39;</span><span class="se">\n</span><span class="s">&lt;/tr&gt;</span><span class="se">\n</span><span class="s">&#39;</span>
        <span class="n">s</span> <span class="o">+=</span> <span class="s">&quot;&quot;&quot;</span>
<span class="s">&lt;/table&gt;&lt;br&gt;</span>
<span class="s">&lt;input type=&quot;submit&quot; value=&quot;simulate and visualize&quot; name=&quot;sim&quot;&gt;</span>
<span class="s">&lt;/form&gt;</span>
<span class="s">&quot;&quot;&quot;</span>
        <span class="c"># perform simulation and visualization as next step</span>
        <span class="c">#return s</span>
        <span class="k">print</span> <span class="n">s</span>
</div>
<div class="viewcode-block" id="AutoSimVizCGI.footer"><a class="viewcode-back" href="../../TkGUI.html#scitools.TkGUI.AutoSimVizCGI.footer">[docs]</a>    <span class="k">def</span> <span class="nf">footer</span><span class="p">(</span><span class="bp">self</span><span class="p">):</span>
        <span class="sd">&quot;&quot;&quot;Write out HTML footer instructions.&quot;&quot;&quot;</span>
        <span class="n">s</span> <span class="o">=</span> <span class="s">&quot;&quot;&quot;</span><span class="se">\n</span><span class="s">&lt;/body&gt;&lt;/html&gt;</span><span class="se">\n</span><span class="s">&quot;&quot;&quot;</span>
        <span class="c">#return s</span>
        <span class="k">print</span> <span class="n">s</span>
</div></div>
<span class="k">def</span> <span class="nf">_test1_Parameters</span><span class="p">():</span>
    <span class="n">d</span> <span class="o">=</span> <span class="p">{</span><span class="s">&#39;A&#39;</span><span class="p">:</span> <span class="mf">1.0</span><span class="p">,</span> <span class="s">&#39;w&#39;</span><span class="p">:</span> <span class="mf">0.2</span><span class="p">,</span> <span class="s">&#39;func&#39;</span><span class="p">:</span> <span class="s">&#39;siny&#39;</span><span class="p">,</span> <span class="s">&#39;y0&#39;</span><span class="p">:</span> <span class="mf">0.0</span><span class="p">}</span>
    <span class="n">p</span> <span class="o">=</span> <span class="n">Parameters</span><span class="p">(</span><span class="n">interface</span><span class="o">=</span><span class="s">&#39;GUI&#39;</span><span class="p">,</span> <span class="n">prm_dict</span><span class="o">=</span><span class="n">d</span><span class="p">)</span>
    <span class="n">p</span><span class="p">[</span><span class="s">&#39;w&#39;</span><span class="p">]</span> <span class="o">=</span> <span class="mf">0.1</span>
    <span class="n">p</span><span class="o">.</span><span class="n">add</span><span class="p">(</span><span class="s">&#39;tstop&#39;</span><span class="p">,</span> <span class="mf">2.0</span><span class="p">,</span> <span class="n">widget_type</span><span class="o">=</span><span class="s">&#39;slider&#39;</span><span class="p">,</span> <span class="n">values</span><span class="o">=</span><span class="p">(</span><span class="mi">0</span><span class="p">,</span><span class="mi">10</span><span class="p">))</span>
    <span class="n">p</span><span class="o">.</span><span class="n">add</span><span class="p">(</span><span class="s">&#39;plot&#39;</span><span class="p">,</span> <span class="bp">False</span><span class="p">)</span>
    <span class="n">d</span> <span class="o">=</span> <span class="n">p</span><span class="o">.</span><span class="n">get</span><span class="p">()</span>
    <span class="k">print</span> <span class="n">d</span>
    <span class="k">print</span> <span class="nb">repr</span><span class="p">(</span><span class="n">p</span><span class="p">)</span>
    <span class="n">p</span><span class="p">[</span><span class="s">&#39;plot&#39;</span><span class="p">]</span> <span class="o">=</span> <span class="bp">True</span>
    <span class="k">for</span> <span class="n">name</span> <span class="ow">in</span> <span class="n">p</span><span class="p">:</span>
        <span class="k">print</span> <span class="s">&#39;p[</span><span class="si">%s</span><span class="s">]=</span><span class="si">%s</span><span class="s">&#39;</span> <span class="o">%</span> <span class="p">(</span><span class="n">name</span><span class="p">,</span> <span class="n">p</span><span class="p">[</span><span class="n">name</span><span class="p">])</span>
    <span class="k">return</span> <span class="n">p</span>

<span class="k">def</span> <span class="nf">_test1_Parameters_wGUI</span><span class="p">():</span>
    <span class="n">parent</span> <span class="o">=</span> <span class="n">Tkinter</span><span class="o">.</span><span class="n">Tk</span><span class="p">()</span>
    <span class="n">Pmw</span><span class="o">.</span><span class="n">initialise</span><span class="p">(</span><span class="n">parent</span><span class="p">)</span>
    <span class="kn">import</span> <span class="nn">scitools.misc</span>
    <span class="n">scitools</span><span class="o">.</span><span class="n">misc</span><span class="o">.</span><span class="n">fontscheme1</span><span class="p">(</span><span class="n">parent</span><span class="p">)</span>
    <span class="n">p</span> <span class="o">=</span> <span class="n">_test1_Parameters</span><span class="p">()</span>
    <span class="n">parametersGUI</span><span class="p">(</span><span class="n">p</span><span class="p">,</span> <span class="n">parent</span><span class="p">,</span> <span class="n">scrolled</span><span class="o">=</span><span class="bp">False</span><span class="p">)</span>
    <span class="k">def</span> <span class="nf">get</span><span class="p">():</span>
        <span class="k">print</span> <span class="n">p</span><span class="o">.</span><span class="n">get</span><span class="p">()</span>
    <span class="n">Tkinter</span><span class="o">.</span><span class="n">Button</span><span class="p">(</span><span class="n">parent</span><span class="p">,</span> <span class="n">text</span><span class="o">=</span><span class="s">&#39;Dump&#39;</span><span class="p">,</span> <span class="n">command</span><span class="o">=</span><span class="n">get</span><span class="p">)</span><span class="o">.</span><span class="n">pack</span><span class="p">(</span><span class="n">pady</span><span class="o">=</span><span class="mi">10</span><span class="p">)</span>
    <span class="n">Tkinter</span><span class="o">.</span><span class="n">Button</span><span class="p">(</span><span class="n">parent</span><span class="p">,</span> <span class="n">text</span><span class="o">=</span><span class="s">&#39;Quit&#39;</span><span class="p">,</span> <span class="n">command</span><span class="o">=</span><span class="n">parent</span><span class="o">.</span><span class="n">quit</span><span class="p">)</span><span class="o">.</span><span class="n">pack</span><span class="p">(</span><span class="n">pady</span><span class="o">=</span><span class="mi">10</span><span class="p">)</span>
    <span class="n">parent</span><span class="o">.</span><span class="n">mainloop</span><span class="p">()</span>

<span class="k">if</span> <span class="n">__name__</span> <span class="o">==</span> <span class="s">&#39;__main__&#39;</span><span class="p">:</span>
    <span class="n">cmd</span> <span class="o">=</span> <span class="n">sys</span><span class="o">.</span><span class="n">argv</span><span class="p">[</span><span class="mi">1</span><span class="p">]</span> <span class="o">+</span> <span class="s">&#39;(&#39;</span> <span class="o">+</span> <span class="s">&#39;  &#39;</span><span class="o">.</span><span class="n">join</span><span class="p">(</span><span class="n">sys</span><span class="o">.</span><span class="n">argv</span><span class="p">[</span><span class="mi">2</span><span class="p">:])</span> <span class="o">+</span> <span class="s">&#39;)&#39;</span>
    <span class="k">print</span> <span class="n">cmd</span>
    <span class="k">exec</span><span class="p">(</span><span class="n">cmd</span><span class="p">)</span>


<span class="sd">&quot;&quot;&quot;</span>
<span class="sd">Notebook for selecting functions.</span>
<span class="sd">&quot;&quot;&quot;</span>
<span class="kn">import</span> <span class="nn">types</span>
<span class="kn">from</span> <span class="nn">scitools.numpyutils</span> <span class="kn">import</span> <span class="n">seq</span><span class="p">,</span> <span class="n">wrap2callable</span><span class="p">,</span> <span class="n">ndarray</span><span class="p">,</span> <span class="n">pi</span>
<span class="kn">from</span> <span class="nn">scitools.StringFunction</span> <span class="kn">import</span> <span class="n">StringFunction</span>

<div class="viewcode-block" id="FuncSpec"><a class="viewcode-back" href="../../TkGUI.html#scitools.TkGUI.FuncSpec">[docs]</a><span class="k">class</span> <span class="nc">FuncSpec</span><span class="p">:</span>
    <span class="sd">&quot;&quot;&quot;</span>
<span class="sd">    Specification of a function.</span>
<span class="sd">    Lists of such specifications can be fed to class FunctionSelector</span>
<span class="sd">    to form a notebook where each page is designed according to the</span>
<span class="sd">    contents of a FuncSpec object.</span>
<span class="sd">    &quot;&quot;&quot;</span>

<div class="viewcode-block" id="FuncSpec.__init__"><a class="viewcode-back" href="../../TkGUI.html#scitools.TkGUI.FuncSpec.__init__">[docs]</a>    <span class="k">def</span> <span class="nf">__init__</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span>
                 <span class="n">representation</span><span class="p">,</span>
                 <span class="n">name</span><span class="o">=</span><span class="s">&#39;&#39;</span><span class="p">,</span>
                 <span class="n">parameters</span><span class="o">=</span><span class="bp">None</span><span class="p">,</span>
                 <span class="n">independent_variables</span><span class="o">=</span><span class="p">[],</span>
                 <span class="n">formula</span><span class="o">=</span><span class="bp">None</span><span class="p">,</span>
                 <span class="n">image</span><span class="o">=</span><span class="bp">None</span><span class="p">,</span>
                 <span class="n">function_object</span><span class="o">=</span><span class="bp">None</span><span class="p">,</span>
                 <span class="n">vector</span> <span class="o">=</span> <span class="mi">0</span><span class="p">,</span>
                 <span class="n">description</span><span class="o">=</span><span class="bp">None</span><span class="p">,</span>
                 <span class="n">xcoor</span><span class="o">=</span><span class="bp">None</span><span class="p">,</span>
                 <span class="n">scrolled_frame</span><span class="o">=</span><span class="bp">False</span><span class="p">,</span>
                 <span class="p">):</span>
        <span class="sd">&quot;&quot;&quot;</span>
<span class="sd">        Arguments:</span>

<span class="sd">        @param representation:  class Drawing, UserFunction, or</span>
<span class="sd">                                StringFormula</span>
<span class="sd">        @param name:            name of function</span>
<span class="sd">        @param parameters:      parameters in the function, either</span>
<span class="sd">                                dict or Parameters instance</span>
<span class="sd">        @param independent_variables: list/tuple of strings with the</span>
<span class="sd">                                names of the indep. variables.</span>
<span class="sd">        @param formula:         textual doc of function formula</span>
<span class="sd">        @param image:           filename of GIF image (LaTeX)</span>
<span class="sd">        @param function_object: callable object for evaluating the function</span>
<span class="sd">        @param vector:          0: scalar function, &gt;0: no of vector comp.</span>
<span class="sd">        @param description:     more verbose description than formula</span>
<span class="sd">        @param xcoor:           array of coordinates for drawing</span>
<span class="sd">        @param scrolled_frame:  scrollbars in the notebook page, False</span>
<span class="sd">                                or dict: {&#39;width&#39;: 300, &#39;height&#39;:200}</span>

<span class="sd">        Examples: see test_FunctionSelector in TkGUI.py.</span>
<span class="sd">        &quot;&quot;&quot;</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">name</span> <span class="o">=</span> <span class="n">name</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">representation</span> <span class="o">=</span> <span class="n">representation</span>
        <span class="k">if</span> <span class="ow">not</span> <span class="bp">self</span><span class="o">.</span><span class="n">name</span><span class="p">:</span>
            <span class="k">raise</span> <span class="ne">ValueError</span><span class="p">(</span><span class="s">&#39;name keyword must be set when creating a &#39;</span>\
                             <span class="s">&#39;FuncSpec object&#39;</span><span class="p">)</span>

        <span class="bp">self</span><span class="o">.</span><span class="n">configure</span><span class="p">(</span>
            <span class="n">parameters</span><span class="o">=</span><span class="n">parameters</span><span class="p">,</span>
            <span class="n">independent_variables</span><span class="o">=</span><span class="n">independent_variables</span><span class="p">,</span>
            <span class="n">formula</span><span class="o">=</span><span class="n">formula</span><span class="p">,</span>
            <span class="n">image</span><span class="o">=</span><span class="n">image</span><span class="p">,</span>
            <span class="n">function_object</span><span class="o">=</span><span class="n">function_object</span><span class="p">,</span>
            <span class="n">vector</span><span class="o">=</span><span class="n">vector</span><span class="p">,</span>
            <span class="n">description</span><span class="o">=</span><span class="n">description</span><span class="p">,</span>
            <span class="n">xcoor</span><span class="o">=</span><span class="n">xcoor</span><span class="p">,</span>
            <span class="n">scrolled_frame</span><span class="o">=</span><span class="n">scrolled_frame</span><span class="p">)</span>
</div>
<div class="viewcode-block" id="FuncSpec.configure"><a class="viewcode-back" href="../../TkGUI.html#scitools.TkGUI.FuncSpec.configure">[docs]</a>    <span class="k">def</span> <span class="nf">configure</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="o">**</span><span class="n">kwargs</span><span class="p">):</span>
        <span class="k">if</span> <span class="s">&#39;parameters&#39;</span> <span class="ow">in</span> <span class="n">kwargs</span><span class="p">:</span>
            <span class="bp">self</span><span class="o">.</span><span class="n">parameters</span> <span class="o">=</span> <span class="n">kwargs</span><span class="p">[</span><span class="s">&#39;parameters&#39;</span><span class="p">]</span>
        <span class="k">if</span> <span class="bp">self</span><span class="o">.</span><span class="n">parameters</span> <span class="ow">is</span> <span class="ow">not</span> <span class="bp">None</span><span class="p">:</span>
            <span class="k">if</span> <span class="nb">isinstance</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">parameters</span><span class="p">,</span> <span class="nb">dict</span><span class="p">):</span>
                <span class="bp">self</span><span class="o">.</span><span class="n">parameters</span> <span class="o">=</span> \
                   <span class="n">Parameters</span><span class="p">(</span><span class="n">interface</span><span class="o">=</span><span class="s">&#39;GUI&#39;</span><span class="p">,</span> <span class="n">prm_dict</span><span class="o">=</span><span class="bp">self</span><span class="o">.</span><span class="n">parameters</span><span class="p">)</span>
            <span class="k">if</span> <span class="ow">not</span> <span class="nb">isinstance</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">parameters</span><span class="p">,</span> <span class="n">Parameters</span><span class="p">):</span>
                <span class="k">raise</span> <span class="ne">TypeError</span><span class="p">(</span>
                    <span class="s">&#39;parameters must be a dictionary or Parameters object, &#39;</span>\
                    <span class="s">&#39;not a </span><span class="si">%s</span><span class="s">&#39;</span> <span class="o">%</span> <span class="nb">type</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">parameters</span><span class="p">))</span>

        <span class="k">if</span> <span class="s">&#39;independent_variables&#39;</span> <span class="ow">in</span> <span class="n">kwargs</span><span class="p">:</span>
            <span class="bp">self</span><span class="o">.</span><span class="n">independent_variables</span> <span class="o">=</span> <span class="n">kwargs</span><span class="p">[</span><span class="s">&#39;independent_variables&#39;</span><span class="p">]</span>
        <span class="k">if</span> <span class="s">&#39;formula&#39;</span> <span class="ow">in</span> <span class="n">kwargs</span><span class="p">:</span>
            <span class="bp">self</span><span class="o">.</span><span class="n">formula</span> <span class="o">=</span> <span class="n">kwargs</span><span class="p">[</span><span class="s">&#39;formula&#39;</span><span class="p">]</span>
        <span class="k">if</span> <span class="s">&#39;image&#39;</span> <span class="ow">in</span> <span class="n">kwargs</span><span class="p">:</span>
            <span class="bp">self</span><span class="o">.</span><span class="n">image</span> <span class="o">=</span> <span class="n">kwargs</span><span class="p">[</span><span class="s">&#39;image&#39;</span><span class="p">]</span>
        <span class="k">if</span> <span class="s">&#39;function_object&#39;</span> <span class="ow">in</span> <span class="n">kwargs</span><span class="p">:</span>
            <span class="bp">self</span><span class="o">.</span><span class="n">function_object</span> <span class="o">=</span> <span class="n">kwargs</span><span class="p">[</span><span class="s">&#39;function_object&#39;</span><span class="p">]</span>
            <span class="k">if</span> <span class="nb">type</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">function_object</span><span class="p">)</span> <span class="o">==</span> <span class="n">types</span><span class="o">.</span><span class="n">ClassType</span><span class="p">:</span>
                <span class="k">raise</span> <span class="ne">TypeError</span><span class="p">(</span>
                    <span class="s">&#39;class type, not instance, provided as &#39;</span>\
                    <span class="s">&#39;function_object for </span><span class="si">%s</span><span class="s">&#39;</span> <span class="o">%</span> <span class="bp">self</span><span class="o">.</span><span class="n">name</span><span class="p">)</span>
        <span class="k">if</span> <span class="s">&#39;vector&#39;</span> <span class="ow">in</span> <span class="n">kwargs</span><span class="p">:</span>
            <span class="bp">self</span><span class="o">.</span><span class="n">vector</span> <span class="o">=</span> <span class="n">kwargs</span><span class="p">[</span><span class="s">&#39;vector&#39;</span><span class="p">]</span>
        <span class="k">if</span> <span class="s">&#39;description&#39;</span> <span class="ow">in</span> <span class="n">kwargs</span><span class="p">:</span>
            <span class="bp">self</span><span class="o">.</span><span class="n">description</span> <span class="o">=</span> <span class="n">kwargs</span><span class="p">[</span><span class="s">&#39;description&#39;</span><span class="p">]</span>
        <span class="k">if</span> <span class="s">&#39;xcoor&#39;</span> <span class="ow">in</span> <span class="n">kwargs</span><span class="p">:</span>
            <span class="bp">self</span><span class="o">.</span><span class="n">xcoor</span> <span class="o">=</span> <span class="n">kwargs</span><span class="p">[</span><span class="s">&#39;xcoor&#39;</span><span class="p">]</span>
        <span class="k">if</span> <span class="s">&#39;scrolled_frame&#39;</span> <span class="ow">in</span> <span class="n">kwargs</span><span class="p">:</span>
            <span class="bp">self</span><span class="o">.</span><span class="n">scrolled_frame</span> <span class="o">=</span> <span class="n">kwargs</span><span class="p">[</span><span class="s">&#39;scrolled_frame&#39;</span><span class="p">]</span>

        <span class="bp">self</span><span class="o">.</span><span class="n">ok</span><span class="p">()</span>  <span class="c"># check validity of arguments</span>
</div>
<div class="viewcode-block" id="FuncSpec.ok"><a class="viewcode-back" href="../../TkGUI.html#scitools.TkGUI.FuncSpec.ok">[docs]</a>    <span class="k">def</span> <span class="nf">ok</span><span class="p">(</span><span class="bp">self</span><span class="p">):</span>
        <span class="k">if</span> <span class="ow">not</span> <span class="nb">isinstance</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">independent_variables</span><span class="p">,</span> <span class="p">(</span><span class="nb">list</span><span class="p">,</span> <span class="nb">tuple</span><span class="p">)):</span>
            <span class="k">raise</span> <span class="ne">TypeError</span><span class="p">(</span>
                <span class="s">&#39;independent_variables must be list or tuple, not </span><span class="si">%s</span><span class="s">&#39;</span> <span class="o">%</span> \
                <span class="nb">type</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">independent_variables</span><span class="p">))</span>

        <span class="k">if</span> <span class="bp">self</span><span class="o">.</span><span class="n">formula</span> <span class="ow">is</span> <span class="ow">not</span> <span class="bp">None</span><span class="p">:</span>
            <span class="k">if</span> <span class="ow">not</span> <span class="nb">isinstance</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">formula</span><span class="p">,</span> <span class="nb">basestring</span><span class="p">):</span>
                <span class="k">raise</span> <span class="ne">TypeError</span><span class="p">(</span>
                    <span class="s">&#39;formula must be string, not </span><span class="si">%s</span><span class="s">&#39;</span> <span class="o">%</span> <span class="nb">type</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">formula</span><span class="p">))</span>

        <span class="k">if</span> <span class="bp">self</span><span class="o">.</span><span class="n">image</span> <span class="ow">is</span> <span class="ow">not</span> <span class="bp">None</span><span class="p">:</span>
            <span class="k">if</span> <span class="ow">not</span> <span class="nb">isinstance</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">image</span><span class="p">,</span> <span class="nb">basestring</span><span class="p">):</span>
                <span class="k">raise</span> <span class="ne">TypeError</span><span class="p">(</span>
                    <span class="s">&#39;image must be string (filename), not </span><span class="si">%s</span><span class="s">&#39;</span> <span class="o">%</span> \
                    <span class="nb">type</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">image</span><span class="p">))</span>
            <span class="k">if</span> <span class="ow">not</span> <span class="n">os</span><span class="o">.</span><span class="n">path</span><span class="o">.</span><span class="n">isfile</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">image</span><span class="p">):</span>
                <span class="k">raise</span> <span class="ne">ValueError</span><span class="p">(</span><span class="s">&#39;file </span><span class="si">%s</span><span class="s"> not found&#39;</span> <span class="o">%</span> <span class="bp">self</span><span class="o">.</span><span class="n">image</span><span class="p">)</span>

        <span class="k">if</span> <span class="ow">not</span> <span class="nb">isinstance</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">vector</span><span class="p">,</span> <span class="nb">int</span><span class="p">):</span>
            <span class="k">raise</span> <span class="ne">TypeError</span><span class="p">(</span>
                <span class="s">&#39;vector must be int (0=scalar, &gt;=1: no of vector comp.), &#39;</span>\
                <span class="s">&#39;not </span><span class="si">%s</span><span class="s">&#39;</span> <span class="o">%</span> <span class="nb">type</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">vector</span><span class="p">))</span>

        <span class="k">if</span> <span class="bp">self</span><span class="o">.</span><span class="n">description</span> <span class="ow">is</span> <span class="ow">not</span> <span class="bp">None</span><span class="p">:</span>
            <span class="k">if</span> <span class="ow">not</span> <span class="nb">isinstance</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">description</span><span class="p">,</span> <span class="nb">basestring</span><span class="p">):</span>
                <span class="k">raise</span> <span class="ne">TypeError</span><span class="p">(</span>
                    <span class="s">&#39;description must be string, not </span><span class="si">%s</span><span class="s">&#39;</span> <span class="o">%</span> \
                    <span class="nb">type</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">description</span><span class="p">))</span>

        <span class="k">if</span> <span class="bp">self</span><span class="o">.</span><span class="n">xcoor</span> <span class="ow">is</span> <span class="ow">not</span> <span class="bp">None</span><span class="p">:</span>
            <span class="k">if</span> <span class="ow">not</span> <span class="nb">isinstance</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">xcoor</span><span class="p">,</span> <span class="n">ndarray</span><span class="p">):</span>
                <span class="k">raise</span> <span class="ne">TypeError</span><span class="p">(</span>
                    <span class="s">&#39;xcoor must be a NumPy array, not </span><span class="si">%s</span><span class="s">&#39;</span> <span class="o">%</span> <span class="nb">type</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">xcoor</span><span class="p">))</span>

        <span class="k">if</span> <span class="bp">self</span><span class="o">.</span><span class="n">scrolled_frame</span> <span class="o">!=</span> <span class="bp">False</span><span class="p">:</span>
            <span class="k">if</span> <span class="ow">not</span> <span class="nb">isinstance</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">scrolled_frame</span><span class="p">,</span> <span class="nb">dict</span><span class="p">):</span>
                <span class="k">raise</span> <span class="ne">TypeError</span><span class="p">(</span><span class="s">&#39;scrolled_frame must be True or dict, &#39;</span>\
                                <span class="s">&#39;not </span><span class="si">%s</span><span class="s">&#39;</span> <span class="o">%</span> <span class="nb">type</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">scrolled_frame</span><span class="p">))</span>

</div>
<div class="viewcode-block" id="FuncSpec.get_independent_variables"><a class="viewcode-back" href="../../TkGUI.html#scitools.TkGUI.FuncSpec.get_independent_variables">[docs]</a>    <span class="k">def</span> <span class="nf">get_independent_variables</span><span class="p">(</span><span class="bp">self</span><span class="p">):</span>
        <span class="k">if</span> <span class="ow">not</span> <span class="bp">self</span><span class="o">.</span><span class="n">independent_variables</span><span class="p">:</span>
            <span class="k">raise</span> <span class="ne">ValueError</span><span class="p">(</span><span class="s">&#39;FuncSpec for &quot;</span><span class="si">%s</span><span class="s">&quot; has no list of independent &#39;</span>\
                             <span class="s">&#39;variables&#39;</span> <span class="o">%</span> <span class="bp">self</span><span class="o">.</span><span class="n">name</span><span class="p">)</span>
        <span class="n">text</span> <span class="o">=</span> <span class="s">&#39;independent variable&#39;</span>
        <span class="k">if</span> <span class="nb">len</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">independent_variables</span><span class="p">)</span> <span class="o">&gt;</span> <span class="mi">1</span><span class="p">:</span>
            <span class="n">text</span> <span class="o">+=</span> <span class="s">&#39;s&#39;</span>
        <span class="n">text</span> <span class="o">+=</span> <span class="s">&#39;: &#39;</span> <span class="o">+</span> <span class="s">&#39;, &#39;</span><span class="o">.</span><span class="n">join</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">independent_variables</span><span class="p">)</span>
        <span class="k">return</span> <span class="n">text</span>
</div>
<div class="viewcode-block" id="FuncSpec.__repr__"><a class="viewcode-back" href="../../TkGUI.html#scitools.TkGUI.FuncSpec.__repr__">[docs]</a>    <span class="k">def</span> <span class="nf">__repr__</span><span class="p">(</span><span class="bp">self</span><span class="p">):</span>
        <span class="n">args</span> <span class="o">=</span> <span class="p">[]</span>
        <span class="k">for</span> <span class="n">key</span> <span class="ow">in</span> <span class="bp">self</span><span class="o">.</span><span class="n">__dict__</span><span class="p">:</span>
            <span class="k">if</span> <span class="bp">self</span><span class="o">.</span><span class="n">__dict__</span><span class="p">[</span><span class="n">key</span><span class="p">]</span> <span class="ow">is</span> <span class="ow">not</span> <span class="bp">None</span><span class="p">:</span>
                <span class="n">args</span><span class="o">.</span><span class="n">append</span><span class="p">(</span><span class="s">&#39;</span><span class="si">%s</span><span class="s">=</span><span class="si">%s</span><span class="s">&#39;</span> <span class="o">%</span> <span class="p">(</span><span class="n">key</span><span class="p">,</span><span class="bp">self</span><span class="o">.</span><span class="n">__dict__</span><span class="p">[</span><span class="n">key</span><span class="p">]))</span>
        <span class="k">return</span> <span class="s">&#39;FuncSpec(&#39;</span> <span class="o">+</span> <span class="s">&#39;, &#39;</span><span class="o">.</span><span class="n">join</span><span class="p">(</span><span class="n">args</span><span class="p">)</span> <span class="o">+</span> <span class="s">&#39;)&#39;</span>

</div></div>
<div class="viewcode-block" id="StringFormula"><a class="viewcode-back" href="../../TkGUI.html#scitools.TkGUI.StringFormula">[docs]</a><span class="k">class</span> <span class="nc">StringFormula</span><span class="p">:</span>
<div class="viewcode-block" id="StringFormula.__init__"><a class="viewcode-back" href="../../TkGUI.html#scitools.TkGUI.StringFormula.__init__">[docs]</a>    <span class="k">def</span> <span class="nf">__init__</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">parent</span><span class="p">,</span> <span class="n">func_spec</span><span class="p">):</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">fspec</span> <span class="o">=</span> <span class="n">func_spec</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">master</span> <span class="o">=</span> <span class="n">parent</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">top</span> <span class="o">=</span> <span class="n">Tkinter</span><span class="o">.</span><span class="n">Frame</span><span class="p">(</span><span class="n">parent</span><span class="p">,</span> <span class="n">borderwidth</span><span class="o">=</span><span class="mi">2</span><span class="p">)</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">top</span><span class="o">.</span><span class="n">pack</span><span class="p">(</span><span class="n">side</span><span class="o">=</span><span class="s">&#39;top&#39;</span><span class="p">)</span>

        <span class="c"># note that StringFunction works for scalar and vector fields!</span>
        <span class="c"># just use [formula_x, formula_y]</span>

        <span class="bp">self</span><span class="o">.</span><span class="n">formula</span> <span class="o">=</span> <span class="n">Tkinter</span><span class="o">.</span><span class="n">StringVar</span><span class="p">()</span>
        <span class="k">if</span> <span class="bp">self</span><span class="o">.</span><span class="n">fspec</span><span class="o">.</span><span class="n">formula</span> <span class="ow">is</span> <span class="ow">not</span> <span class="bp">None</span><span class="p">:</span>
            <span class="bp">self</span><span class="o">.</span><span class="n">formula</span><span class="o">.</span><span class="n">set</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">fspec</span><span class="o">.</span><span class="n">formula</span><span class="p">)</span>

        <span class="bp">self</span><span class="o">.</span><span class="n">widget</span> <span class="o">=</span> <span class="n">Pmw</span><span class="o">.</span><span class="n">EntryField</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">top</span><span class="p">,</span>
                      <span class="n">labelpos</span><span class="o">=</span><span class="s">&#39;n&#39;</span><span class="p">,</span>
                      <span class="n">label_text</span><span class="o">=</span><span class="bp">self</span><span class="o">.</span><span class="n">fspec</span><span class="o">.</span><span class="n">get_independent_variables</span><span class="p">(),</span>
                      <span class="n">entry_width</span><span class="o">=</span><span class="mi">15</span><span class="p">,</span>
                      <span class="n">entry_textvariable</span><span class="o">=</span><span class="bp">self</span><span class="o">.</span><span class="n">formula</span><span class="p">)</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">widget</span><span class="o">.</span><span class="n">pack</span><span class="p">(</span><span class="n">pady</span><span class="o">=</span><span class="mi">5</span><span class="p">)</span>

        <span class="k">if</span> <span class="bp">self</span><span class="o">.</span><span class="n">fspec</span><span class="o">.</span><span class="n">parameters</span><span class="p">:</span>
            <span class="n">parametersGUI</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">fspec</span><span class="o">.</span><span class="n">parameters</span><span class="p">,</span> <span class="bp">self</span><span class="o">.</span><span class="n">top</span><span class="p">,</span>
                          <span class="n">scrolled</span><span class="o">=</span><span class="bp">self</span><span class="o">.</span><span class="n">fspec</span><span class="o">.</span><span class="n">scrolled_frame</span><span class="p">)</span>
</div>
<div class="viewcode-block" id="StringFormula.get"><a class="viewcode-back" href="../../TkGUI.html#scitools.TkGUI.StringFormula.get">[docs]</a>    <span class="k">def</span> <span class="nf">get</span><span class="p">(</span><span class="bp">self</span><span class="p">):</span>
        <span class="sd">&quot;&quot;&quot;Return function object.&quot;&quot;&quot;</span>
        <span class="n">f</span> <span class="o">=</span> <span class="n">StringFunction</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">formula</span><span class="o">.</span><span class="n">get</span><span class="p">(),</span>
            <span class="n">independent_variables</span><span class="o">=</span><span class="bp">self</span><span class="o">.</span><span class="n">fspec</span><span class="o">.</span><span class="n">independent_variables</span><span class="p">)</span>
        <span class="k">if</span> <span class="bp">self</span><span class="o">.</span><span class="n">fspec</span><span class="o">.</span><span class="n">parameters</span><span class="p">:</span>
            <span class="c"># turn parameters object into dictionary and send</span>
            <span class="c"># this as keyword arguments to StringFunction.set_parameters</span>
            <span class="n">f</span><span class="o">.</span><span class="n">set_parameters</span><span class="p">(</span><span class="o">**</span><span class="bp">self</span><span class="o">.</span><span class="n">fspec</span><span class="o">.</span><span class="n">parameters</span><span class="o">.</span><span class="n">get</span><span class="p">())</span>
        <span class="k">return</span> <span class="n">wrap2callable</span><span class="p">(</span><span class="n">f</span><span class="p">)</span>


</div></div>
<div class="viewcode-block" id="UserFunction"><a class="viewcode-back" href="../../TkGUI.html#scitools.TkGUI.UserFunction">[docs]</a><span class="k">class</span> <span class="nc">UserFunction</span><span class="p">:</span>
<div class="viewcode-block" id="UserFunction.__init__"><a class="viewcode-back" href="../../TkGUI.html#scitools.TkGUI.UserFunction.__init__">[docs]</a>    <span class="k">def</span> <span class="nf">__init__</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">parent</span><span class="p">,</span> <span class="n">func_spec</span><span class="p">):</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">fspec</span> <span class="o">=</span> <span class="n">func_spec</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">master</span> <span class="o">=</span> <span class="n">parent</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">top</span> <span class="o">=</span> <span class="n">Tkinter</span><span class="o">.</span><span class="n">Frame</span><span class="p">(</span><span class="n">parent</span><span class="p">,</span> <span class="n">borderwidth</span><span class="o">=</span><span class="mi">2</span><span class="p">)</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">top</span><span class="o">.</span><span class="n">pack</span><span class="p">(</span><span class="n">side</span><span class="o">=</span><span class="s">&#39;top&#39;</span><span class="p">)</span>
        <span class="n">Tkinter</span><span class="o">.</span><span class="n">Label</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">top</span><span class="p">,</span>
        <span class="n">text</span><span class="o">=</span><span class="bp">self</span><span class="o">.</span><span class="n">fspec</span><span class="o">.</span><span class="n">get_independent_variables</span><span class="p">())</span><span class="o">.</span><span class="n">pack</span><span class="p">()</span>
        <span class="k">if</span> <span class="bp">self</span><span class="o">.</span><span class="n">fspec</span><span class="o">.</span><span class="n">formula</span><span class="p">:</span>
            <span class="n">width</span> <span class="o">=</span> <span class="nb">min</span><span class="p">(</span><span class="nb">len</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">fspec</span><span class="o">.</span><span class="n">formula</span><span class="p">)</span><span class="o">+</span><span class="mi">5</span><span class="p">,</span> <span class="mi">30</span><span class="p">)</span>
            <span class="n">Tkinter</span><span class="o">.</span><span class="n">Label</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">top</span><span class="p">,</span> <span class="n">text</span><span class="o">=</span><span class="bp">self</span><span class="o">.</span><span class="n">fspec</span><span class="o">.</span><span class="n">formula</span><span class="p">,</span>
                          <span class="n">width</span><span class="o">=</span><span class="n">width</span><span class="p">)</span><span class="o">.</span><span class="n">pack</span><span class="p">()</span>
        <span class="k">else</span><span class="p">:</span>
            <span class="k">print</span> <span class="s">&#39;Warning: UserFunction, name=</span><span class="si">%s</span><span class="s">, has no formula!&#39;</span> <span class="o">%</span> \
                  <span class="bp">self</span><span class="o">.</span><span class="n">fspec</span><span class="o">.</span><span class="n">name</span>
            <span class="n">Tkinter</span><span class="o">.</span><span class="n">Label</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">top</span><span class="p">,</span> <span class="n">text</span><span class="o">=</span><span class="s">&#39;no function expression known&#39;</span><span class="p">)</span><span class="o">.</span><span class="n">pack</span><span class="p">()</span>
        <span class="k">if</span> <span class="bp">self</span><span class="o">.</span><span class="n">fspec</span><span class="o">.</span><span class="n">parameters</span><span class="p">:</span>
            <span class="k">print</span> <span class="bp">self</span><span class="o">.</span><span class="n">fspec</span><span class="o">.</span><span class="n">parameters</span><span class="p">,</span> <span class="nb">type</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">fspec</span><span class="o">.</span><span class="n">parameters</span><span class="p">)</span>
            <span class="n">Tkinter</span><span class="o">.</span><span class="n">Label</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">top</span><span class="p">,</span> <span class="n">text</span><span class="o">=</span><span class="s">&#39;parameters: &#39;</span> <span class="o">+</span>
                          <span class="s">&#39;, &#39;</span><span class="o">.</span><span class="n">join</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">fspec</span><span class="o">.</span><span class="n">parameters</span><span class="o">.</span><span class="n">keys</span><span class="p">()))</span><span class="o">.</span><span class="n">pack</span><span class="p">()</span>

        <span class="k">if</span> <span class="bp">self</span><span class="o">.</span><span class="n">fspec</span><span class="o">.</span><span class="n">image</span> <span class="ow">is</span> <span class="ow">not</span> <span class="bp">None</span><span class="p">:</span>
            <span class="bp">self</span><span class="o">.</span><span class="n">image</span> <span class="o">=</span> <span class="n">Tkinter</span><span class="o">.</span><span class="n">PhotoImage</span><span class="p">(</span><span class="nb">file</span><span class="o">=</span><span class="bp">self</span><span class="o">.</span><span class="n">fspec</span><span class="o">.</span><span class="n">image</span><span class="p">)</span>
            <span class="n">Tkinter</span><span class="o">.</span><span class="n">Label</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">top</span><span class="p">,</span> <span class="n">image</span><span class="o">=</span><span class="bp">self</span><span class="o">.</span><span class="n">image</span><span class="p">)</span><span class="o">.</span><span class="n">pack</span><span class="p">()</span>

        <span class="c"># widgets for setting parameters:</span>
        <span class="k">if</span> <span class="bp">self</span><span class="o">.</span><span class="n">fspec</span><span class="o">.</span><span class="n">parameters</span><span class="p">:</span>
            <span class="n">parametersGUI</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">fspec</span><span class="o">.</span><span class="n">parameters</span><span class="p">,</span> <span class="bp">self</span><span class="o">.</span><span class="n">top</span><span class="p">,</span>
                          <span class="n">pack_side</span><span class="o">=</span><span class="s">&#39;top&#39;</span><span class="p">,</span><span class="n">scrolled</span><span class="o">=</span><span class="bp">self</span><span class="o">.</span><span class="n">fspec</span><span class="o">.</span><span class="n">scrolled_frame</span><span class="p">)</span>
</div>
<div class="viewcode-block" id="UserFunction.get"><a class="viewcode-back" href="../../TkGUI.html#scitools.TkGUI.UserFunction.get">[docs]</a>    <span class="k">def</span> <span class="nf">get</span><span class="p">(</span><span class="bp">self</span><span class="p">):</span>
        <span class="sd">&quot;&quot;&quot;Return function object.&quot;&quot;&quot;</span>
        <span class="c"># extract parameter values from the GUI?</span>
        <span class="k">if</span> <span class="bp">self</span><span class="o">.</span><span class="n">fspec</span><span class="o">.</span><span class="n">parameters</span><span class="p">:</span>
            <span class="n">d</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">fspec</span><span class="o">.</span><span class="n">parameters</span><span class="o">.</span><span class="n">get</span><span class="p">()</span>  <span class="c"># dict of (name,value) pairs</span>
            <span class="k">for</span> <span class="n">name</span> <span class="ow">in</span> <span class="n">d</span><span class="p">:</span>
                <span class="k">try</span><span class="p">:</span>
                    <span class="n">f</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">fspec</span><span class="o">.</span><span class="n">function_object</span>
                <span class="k">except</span><span class="p">:</span>
                    <span class="k">raise</span> <span class="ne">AttributeError</span><span class="p">(</span>
                        <span class="s">&#39;FuncSpec &quot;</span><span class="si">%s</span><span class="s">&quot; used in UserFunction has &#39;</span>\
                        <span class="s">&#39;no function_object set&#39;</span> <span class="o">%</span> <span class="bp">self</span><span class="o">.</span><span class="n">fspec</span><span class="o">.</span><span class="n">name</span><span class="p">)</span>
                <span class="k">if</span> <span class="nb">hasattr</span><span class="p">(</span><span class="n">f</span><span class="p">,</span> <span class="n">name</span><span class="p">):</span>
                    <span class="nb">setattr</span><span class="p">(</span><span class="n">f</span><span class="p">,</span> <span class="n">name</span><span class="p">,</span> <span class="n">d</span><span class="p">[</span><span class="n">name</span><span class="p">])</span>
                <span class="k">else</span><span class="p">:</span>
                    <span class="k">raise</span> <span class="ne">NameError</span><span class="p">(</span><span class="s">&#39;expected parameter name </span><span class="si">%s</span><span class="s"> &#39;</span>\
                                    <span class="s">&#39;as attribute in function object &#39;</span>\
                                    <span class="s">&#39;</span><span class="se">\n</span><span class="s">(dir(function object)=</span><span class="si">%s</span><span class="s">)&#39;</span> <span class="o">%</span> \
                                    <span class="p">(</span><span class="n">name</span><span class="p">,</span><span class="nb">dir</span><span class="p">(</span><span class="n">f</span><span class="p">)))</span>
        <span class="k">return</span> <span class="n">wrap2callable</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">fspec</span><span class="o">.</span><span class="n">function_object</span><span class="p">)</span>

</div></div>
<div class="viewcode-block" id="Drawing"><a class="viewcode-back" href="../../TkGUI.html#scitools.TkGUI.Drawing">[docs]</a><span class="k">class</span> <span class="nc">Drawing</span><span class="p">(</span><span class="n">UserFunction</span><span class="p">):</span>
<div class="viewcode-block" id="Drawing.__init__"><a class="viewcode-back" href="../../TkGUI.html#scitools.TkGUI.Drawing.__init__">[docs]</a>    <span class="k">def</span> <span class="nf">__init__</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">parent</span><span class="p">,</span> <span class="n">func_spec</span><span class="p">):</span>
        <span class="n">UserFunction</span><span class="o">.</span><span class="n">__init__</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">parent</span><span class="p">,</span> <span class="n">func_spec</span><span class="p">)</span>
        <span class="k">if</span> <span class="bp">self</span><span class="o">.</span><span class="n">fspec</span><span class="o">.</span><span class="n">xcoor</span> <span class="ow">is</span> <span class="bp">None</span><span class="p">:</span>
            <span class="k">raise</span> <span class="ne">ValueError</span><span class="p">(</span><span class="s">&#39;want DrawFunction widget, but no xcoor info&#39;</span>\
                             <span class="s">&#39; in the FuncSpec object&#39;</span><span class="p">)</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">drawing</span> <span class="o">=</span> <span class="n">DrawFunction</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">fspec</span><span class="o">.</span><span class="n">xcoor</span><span class="p">,</span> <span class="bp">self</span><span class="o">.</span><span class="n">top</span><span class="p">)</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">drawing</span><span class="o">.</span><span class="n">pack</span><span class="p">(</span><span class="n">padx</span><span class="o">=</span><span class="mi">10</span><span class="p">,</span> <span class="n">pady</span><span class="o">=</span><span class="mi">10</span><span class="p">)</span>
</div>
<div class="viewcode-block" id="Drawing.get"><a class="viewcode-back" href="../../TkGUI.html#scitools.TkGUI.Drawing.get">[docs]</a>    <span class="k">def</span> <span class="nf">get</span><span class="p">(</span><span class="bp">self</span><span class="p">):</span>
        <span class="sd">&quot;&quot;&quot;Return function object.&quot;&quot;&quot;</span>
        <span class="n">x</span><span class="p">,</span> <span class="n">y</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">drawing</span><span class="o">.</span><span class="n">get</span><span class="p">()</span>
        <span class="n">d</span> <span class="o">=</span> <span class="n">wrap2callable</span><span class="p">((</span><span class="n">x</span><span class="p">,</span><span class="n">y</span><span class="p">))</span>
        <span class="c"># The drawing function d may be combined with another</span>
        <span class="c"># expression, forming a new function object. This functionality</span>
        <span class="c"># is in a method &#39;embed&#39; in self.func_spec.function_object.</span>
        <span class="k">try</span><span class="p">:</span>
            <span class="n">f</span> <span class="o">=</span> <span class="n">UserFunction</span><span class="o">.</span><span class="n">get</span><span class="p">(</span><span class="bp">self</span><span class="p">)</span>
            <span class="n">f</span><span class="o">.</span><span class="n">attach_func</span><span class="p">(</span><span class="n">d</span><span class="p">)</span>
            <span class="n">d</span> <span class="o">=</span> <span class="n">f</span>
        <span class="k">except</span><span class="p">:</span>
            <span class="k">pass</span> <span class="c"># no combination with other functions registered</span>
        <span class="k">return</span> <span class="n">d</span>

</div></div>
<div class="viewcode-block" id="FunctionChoices"><a class="viewcode-back" href="../../TkGUI.html#scitools.TkGUI.FunctionChoices">[docs]</a><span class="k">class</span> <span class="nc">FunctionChoices</span><span class="p">:</span>
    <span class="sd">&quot;&quot;&quot;</span>
<span class="sd">    Notebook for various representations of a function.</span>
<span class="sd">    The representations appear as pages. Each page is</span>
<span class="sd">    realized as a UserFunction, StringFormula, or Drawing</span>
<span class="sd">    instance.</span>
<span class="sd">    &quot;&quot;&quot;</span>
<div class="viewcode-block" id="FunctionChoices.__init__"><a class="viewcode-back" href="../../TkGUI.html#scitools.TkGUI.FunctionChoices.__init__">[docs]</a>    <span class="k">def</span> <span class="nf">__init__</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">parent</span><span class="p">,</span> <span class="n">func_spec_list</span><span class="p">):</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">master</span> <span class="o">=</span> <span class="n">parent</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">top</span> <span class="o">=</span> <span class="n">Tkinter</span><span class="o">.</span><span class="n">Frame</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">master</span><span class="p">,</span> <span class="n">borderwidth</span><span class="o">=</span><span class="mi">2</span><span class="p">)</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">top</span><span class="o">.</span><span class="n">pack</span><span class="p">(</span><span class="n">expand</span><span class="o">=</span><span class="bp">True</span><span class="p">,</span> <span class="n">fill</span><span class="o">=</span><span class="s">&#39;both&#39;</span><span class="p">)</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">nb</span> <span class="o">=</span> <span class="n">Pmw</span><span class="o">.</span><span class="n">NoteBook</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">top</span><span class="p">)</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">func_spec_list</span> <span class="o">=</span> <span class="n">func_spec_list</span> <span class="c"># list of FuncSpec objects</span>
        <span class="c"># hold UserFunction, Drawing, or StringFormula objects,</span>
        <span class="c"># one for each page (key is page name):</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">page</span> <span class="o">=</span> <span class="p">{}</span>

        <span class="k">for</span> <span class="n">f</span> <span class="ow">in</span> <span class="bp">self</span><span class="o">.</span><span class="n">func_spec_list</span><span class="p">:</span>
            <span class="c"># define a page:</span>
            <span class="n">new_page</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">nb</span><span class="o">.</span><span class="n">add</span><span class="p">(</span><span class="n">f</span><span class="o">.</span><span class="n">name</span><span class="p">,</span> <span class="n">tab_text</span><span class="o">=</span><span class="n">f</span><span class="o">.</span><span class="n">name</span><span class="p">)</span>
            <span class="c"># group is a kind of frame widget with a solid border:</span>
            <span class="n">group</span> <span class="o">=</span> <span class="n">Pmw</span><span class="o">.</span><span class="n">Group</span><span class="p">(</span><span class="n">new_page</span><span class="p">,</span> <span class="n">tag_text</span><span class="o">=</span><span class="n">f</span><span class="o">.</span><span class="n">name</span><span class="p">)</span>
            <span class="n">group</span><span class="o">.</span><span class="n">pack</span><span class="p">(</span><span class="n">fill</span><span class="o">=</span><span class="s">&#39;both&#39;</span><span class="p">,</span> <span class="n">expand</span><span class="o">=</span><span class="mi">1</span><span class="p">,</span> <span class="n">padx</span><span class="o">=</span><span class="mi">10</span><span class="p">,</span> <span class="n">pady</span><span class="o">=</span><span class="mi">10</span><span class="p">)</span>
            <span class="c"># build contents in current page:</span>
            <span class="bp">self</span><span class="o">.</span><span class="n">page</span><span class="p">[</span><span class="n">f</span><span class="o">.</span><span class="n">name</span><span class="p">]</span> <span class="o">=</span> \
                          <span class="n">f</span><span class="o">.</span><span class="n">representation</span><span class="p">(</span><span class="n">group</span><span class="o">.</span><span class="n">interior</span><span class="p">(),</span> <span class="n">f</span><span class="p">)</span>

        <span class="bp">self</span><span class="o">.</span><span class="n">nb</span><span class="o">.</span><span class="n">pack</span><span class="p">(</span><span class="n">padx</span><span class="o">=</span><span class="mi">5</span><span class="p">,</span> <span class="n">pady</span><span class="o">=</span><span class="mi">5</span><span class="p">,</span> <span class="n">fill</span><span class="o">=</span><span class="s">&#39;both&#39;</span><span class="p">,</span> <span class="n">expand</span><span class="o">=</span><span class="mi">1</span><span class="p">)</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">nb</span><span class="o">.</span><span class="n">setnaturalsize</span><span class="p">()</span>
</div>
<div class="viewcode-block" id="FunctionChoices.get"><a class="viewcode-back" href="../../TkGUI.html#scitools.TkGUI.FunctionChoices.get">[docs]</a>    <span class="k">def</span> <span class="nf">get</span><span class="p">(</span><span class="bp">self</span><span class="p">):</span>
        <span class="sd">&quot;&quot;&quot;</span>
<span class="sd">        Return initialized function object corresponding to</span>
<span class="sd">        the currently selected notebook page.</span>
<span class="sd">        &quot;&quot;&quot;</span>
        <span class="c"># get user-chosen page name:</span>
        <span class="n">current</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">nb</span><span class="o">.</span><span class="n">getcurselection</span><span class="p">()</span>
        <span class="c"># get corresponding function object (self.page[current]</span>
        <span class="c"># is a UserFunction, Drawing, or StringFunction instance):</span>
        <span class="n">f</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">page</span><span class="p">[</span><span class="n">current</span><span class="p">]</span><span class="o">.</span><span class="n">get</span><span class="p">()</span>
        <span class="c">#from scitools.misc import dump</span>
        <span class="c">#dump(f, hide_nonpublic=False)</span>
        <span class="k">return</span> <span class="n">f</span><span class="p">,</span> <span class="n">current</span>
</div></div>
<div class="viewcode-block" id="FunctionSelector"><a class="viewcode-back" href="../../TkGUI.html#scitools.TkGUI.FunctionSelector">[docs]</a><span class="k">class</span> <span class="nc">FunctionSelector</span><span class="p">:</span>
    <span class="sd">&quot;&quot;&quot;</span>
<span class="sd">    Notebook with a collection of functions to be specified.</span>
<span class="sd">    Each function is represented by a FunctionChoices page.</span>
<span class="sd">    This page is again a notebook with pages corresponding to</span>
<span class="sd">    different ways of specifying a function:</span>
<span class="sd">    drawing, string formulas, ready-made formulas with</span>
<span class="sd">    free parameters, hardcoded Python functions etc.</span>
<span class="sd">    &quot;&quot;&quot;</span>
<div class="viewcode-block" id="FunctionSelector.__init__"><a class="viewcode-back" href="../../TkGUI.html#scitools.TkGUI.FunctionSelector.__init__">[docs]</a>    <span class="k">def</span> <span class="nf">__init__</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">parent</span><span class="p">):</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">master</span> <span class="o">=</span> <span class="n">parent</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">top</span> <span class="o">=</span> <span class="n">Tkinter</span><span class="o">.</span><span class="n">Frame</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">master</span><span class="p">,</span> <span class="n">borderwidth</span><span class="o">=</span><span class="mi">2</span><span class="p">)</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">top</span><span class="o">.</span><span class="n">pack</span><span class="p">(</span><span class="n">expand</span><span class="o">=</span><span class="bp">True</span><span class="p">,</span> <span class="n">fill</span><span class="o">=</span><span class="s">&#39;both&#39;</span><span class="p">)</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">nb</span> <span class="o">=</span> <span class="n">Pmw</span><span class="o">.</span><span class="n">NoteBook</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">top</span><span class="p">)</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">page</span> <span class="o">=</span> <span class="p">{}</span>  <span class="c"># FunctionChoices widgets</span>
</div>
<div class="viewcode-block" id="FunctionSelector.add"><a class="viewcode-back" href="../../TkGUI.html#scitools.TkGUI.FunctionSelector.add">[docs]</a>    <span class="k">def</span> <span class="nf">add</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">name</span><span class="p">,</span> <span class="n">func_spec_list</span><span class="p">):</span>
        <span class="n">new_page</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">nb</span><span class="o">.</span><span class="n">add</span><span class="p">(</span><span class="n">name</span><span class="p">,</span> <span class="n">tab_text</span><span class="o">=</span><span class="n">name</span><span class="p">)</span>
        <span class="n">group</span> <span class="o">=</span> <span class="n">Tkinter</span><span class="o">.</span><span class="n">Frame</span><span class="p">(</span><span class="n">new_page</span><span class="p">,</span> <span class="n">borderwidth</span><span class="o">=</span><span class="mi">2</span><span class="p">)</span>
        <span class="n">group</span><span class="o">.</span><span class="n">pack</span><span class="p">(</span><span class="n">expand</span><span class="o">=</span><span class="bp">True</span><span class="p">,</span> <span class="n">fill</span><span class="o">=</span><span class="s">&#39;both&#39;</span><span class="p">)</span>
        <span class="n">w</span> <span class="o">=</span> <span class="n">FunctionChoices</span><span class="p">(</span><span class="n">group</span><span class="p">,</span> <span class="n">func_spec_list</span><span class="p">)</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">page</span><span class="p">[</span><span class="n">name</span><span class="p">]</span> <span class="o">=</span> <span class="n">w</span>
</div>
<div class="viewcode-block" id="FunctionSelector.pack"><a class="viewcode-back" href="../../TkGUI.html#scitools.TkGUI.FunctionSelector.pack">[docs]</a>    <span class="k">def</span> <span class="nf">pack</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="o">**</span><span class="n">kwargs</span><span class="p">):</span>
        <span class="c"># pack notebook:</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">nb</span><span class="o">.</span><span class="n">pack</span><span class="p">(</span><span class="n">padx</span><span class="o">=</span><span class="mi">5</span><span class="p">,</span> <span class="n">pady</span><span class="o">=</span><span class="mi">5</span><span class="p">,</span> <span class="n">fill</span><span class="o">=</span><span class="s">&#39;both&#39;</span><span class="p">,</span> <span class="n">expand</span><span class="o">=</span><span class="mi">1</span><span class="p">,</span> <span class="o">**</span><span class="n">kwargs</span><span class="p">)</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">nb</span><span class="o">.</span><span class="n">setnaturalsize</span><span class="p">()</span>
</div>
<div class="viewcode-block" id="FunctionSelector.select"><a class="viewcode-back" href="../../TkGUI.html#scitools.TkGUI.FunctionSelector.select">[docs]</a>    <span class="k">def</span> <span class="nf">select</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">name</span><span class="p">,</span> <span class="n">page</span><span class="p">):</span>
        <span class="sd">&quot;&quot;&quot;Select page under the name tab.&quot;&quot;&quot;</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">page</span><span class="p">[</span><span class="n">name</span><span class="p">]</span><span class="o">.</span><span class="n">nb</span><span class="o">.</span><span class="n">selectpage</span><span class="p">(</span><span class="n">page</span><span class="p">)</span>
</div>
<div class="viewcode-block" id="FunctionSelector.get"><a class="viewcode-back" href="../../TkGUI.html#scitools.TkGUI.FunctionSelector.get">[docs]</a>    <span class="k">def</span> <span class="nf">get</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">name</span><span class="p">):</span>
        <span class="sd">&quot;&quot;&quot;</span>
<span class="sd">        Return initialized function object corresponding to</span>
<span class="sd">        the page with the given name.</span>
<span class="sd">        &quot;&quot;&quot;</span>
        <span class="k">return</span> <span class="bp">self</span><span class="o">.</span><span class="n">page</span><span class="p">[</span><span class="n">name</span><span class="p">]</span><span class="o">.</span><span class="n">get</span><span class="p">()</span>
        <span class="c">#from scitools.misc import dump</span>
        <span class="c">#dump(f, hide_nonpublic=False)</span>

</div></div>
<div class="viewcode-block" id="test_FunctionChoices"><a class="viewcode-back" href="../../TkGUI.html#scitools.TkGUI.test_FunctionChoices">[docs]</a><span class="k">def</span> <span class="nf">test_FunctionChoices</span><span class="p">(</span><span class="n">root</span><span class="p">):</span>
    <span class="k">class</span> <span class="nc">MyFunc</span><span class="p">:</span>
        <span class="k">def</span> <span class="nf">__init__</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">a</span><span class="p">,</span> <span class="n">b</span><span class="p">):</span>
            <span class="bp">self</span><span class="o">.</span><span class="n">a</span> <span class="o">=</span> <span class="n">a</span><span class="p">;</span>  <span class="bp">self</span><span class="o">.</span><span class="n">b</span> <span class="o">=</span> <span class="n">b</span>
        <span class="k">def</span> <span class="nf">__call__</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">q</span><span class="p">,</span> <span class="n">t</span><span class="p">):</span>
            <span class="k">return</span> <span class="bp">self</span><span class="o">.</span><span class="n">a</span><span class="o">*</span><span class="n">q</span> <span class="o">+</span> <span class="bp">self</span><span class="o">.</span><span class="n">b</span><span class="o">*</span><span class="n">t</span>

    <span class="n">F</span> <span class="o">=</span> <span class="n">FuncSpec</span>
    <span class="n">nb</span> <span class="o">=</span> <span class="p">[</span><span class="n">F</span><span class="p">(</span><span class="n">Drawing</span><span class="p">,</span> <span class="n">name</span><span class="o">=</span><span class="s">&#39;k coeff&#39;</span><span class="p">,</span> <span class="n">xcoor</span><span class="o">=</span><span class="n">seq</span><span class="p">(</span><span class="mi">0</span><span class="p">,</span><span class="mi">1</span><span class="p">,</span><span class="mf">0.01</span><span class="p">)),</span>
          <span class="n">F</span><span class="p">(</span><span class="n">StringFormula</span><span class="p">,</span> <span class="n">name</span><span class="o">=</span><span class="s">&#39;velocity&#39;</span><span class="p">,</span>
            <span class="n">parameters</span><span class="o">=</span><span class="p">{</span><span class="s">&#39;A&#39;</span><span class="p">:</span> <span class="mi">1</span><span class="p">,</span> <span class="s">&#39;B&#39;</span><span class="p">:</span> <span class="mi">1</span><span class="p">,</span> <span class="s">&#39;p&#39;</span><span class="p">:</span> <span class="mi">1</span><span class="p">,</span> <span class="s">&#39;q&#39;</span><span class="p">:</span> <span class="mi">1</span><span class="p">},</span>
            <span class="n">formula</span><span class="o">=</span><span class="s">&#39;[-B*cos(q*y), A*sin(p*x)]&#39;</span><span class="p">,</span>  <span class="c"># vector field</span>
            <span class="n">independent_variables</span><span class="o">=</span><span class="p">(</span><span class="s">&#39;x&#39;</span><span class="p">,</span> <span class="s">&#39;y&#39;</span><span class="p">),</span>
            <span class="n">vector</span><span class="o">=</span><span class="mi">2</span><span class="p">),</span>
          <span class="n">F</span><span class="p">(</span><span class="n">UserFunction</span><span class="p">,</span> <span class="n">name</span><span class="o">=</span><span class="s">&#39;bc&#39;</span><span class="p">,</span>
            <span class="n">parameters</span><span class="o">=</span><span class="p">(</span><span class="s">&#39;a&#39;</span><span class="p">,</span> <span class="s">&#39;b&#39;</span><span class="p">),</span>
            <span class="n">formula</span><span class="o">=</span><span class="s">&#39;a*q + b*t&#39;</span><span class="p">,</span>
            <span class="n">independent_variables</span><span class="o">=</span><span class="p">(</span><span class="s">&#39;q&#39;</span><span class="p">,</span> <span class="s">&#39;t&#39;</span><span class="p">),</span>
            <span class="n">function_object</span><span class="o">=</span><span class="n">MyFunc</span><span class="p">(</span><span class="mi">0</span><span class="p">,</span><span class="mi">0</span><span class="p">)),</span>
          <span class="p">]</span>
    <span class="k">print</span> <span class="n">nb</span>
    <span class="n">gui</span> <span class="o">=</span> <span class="n">FunctionChoices</span><span class="p">(</span><span class="n">root</span><span class="p">,</span> <span class="n">nb</span><span class="p">)</span>
    <span class="n">Tkinter</span><span class="o">.</span><span class="n">Button</span><span class="p">(</span><span class="n">root</span><span class="p">,</span> <span class="n">text</span><span class="o">=</span><span class="s">&#39;get&#39;</span><span class="p">,</span>
                   <span class="c"># note that gui is local so obj=gui is needed to</span>
                   <span class="c"># remember the gui object...</span>
                   <span class="n">command</span><span class="o">=</span><span class="n">gui</span><span class="o">.</span><span class="n">get</span><span class="p">)</span><span class="o">.</span><span class="n">pack</span><span class="p">(</span><span class="n">pady</span><span class="o">=</span><span class="mi">5</span><span class="p">)</span>
    <span class="n">root</span><span class="o">.</span><span class="n">mainloop</span><span class="p">()</span>

</div>
<span class="k">def</span> <span class="nf">_test_FunctionSelector</span><span class="p">(</span><span class="n">root</span><span class="p">):</span>
    <span class="sd">&quot;&quot;&quot;Two-level notebook. Top level: f, I, bc.&quot;&quot;&quot;</span>
    <span class="n">s</span> <span class="o">=</span> <span class="n">FunctionSelector</span><span class="p">(</span><span class="n">root</span><span class="p">)</span>

    <span class="k">class</span> <span class="nc">MovingSource1</span><span class="p">:</span>
        <span class="sd">&quot;&quot;&quot;Function object: A*exp(-(x - x0 - sin(w*t))**2).&quot;&quot;&quot;</span>
        <span class="k">def</span> <span class="nf">__init__</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">A</span><span class="p">,</span> <span class="n">w</span><span class="p">,</span> <span class="n">x0</span><span class="p">):</span>
            <span class="bp">self</span><span class="o">.</span><span class="n">A</span> <span class="o">=</span> <span class="n">A</span><span class="p">;</span> <span class="bp">self</span><span class="o">.</span><span class="n">w</span> <span class="o">=</span> <span class="n">w</span><span class="p">;</span> <span class="bp">self</span><span class="o">.</span><span class="n">x0</span> <span class="o">=</span> <span class="n">x0</span>
        <span class="k">def</span> <span class="nf">__call__</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">x</span><span class="p">,</span> <span class="n">t</span><span class="p">):</span>
            <span class="k">return</span> <span class="bp">self</span><span class="o">.</span><span class="n">A</span><span class="o">*</span><span class="n">exp</span><span class="p">(</span><span class="o">-</span><span class="p">(</span><span class="n">x</span> <span class="o">-</span> <span class="bp">self</span><span class="o">.</span><span class="n">x0</span> <span class="o">-</span> <span class="n">sin</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">w</span><span class="o">*</span><span class="n">t</span><span class="p">))</span><span class="o">**</span><span class="mi">2</span><span class="p">)</span>
        <span class="k">def</span> <span class="nf">__str__</span><span class="p">(</span><span class="bp">self</span><span class="p">):</span>
            <span class="k">return</span> <span class="s">&#39;A*exp(-(x - x0 - sin(w*t))**2)&#39;</span>
        <span class="k">def</span> <span class="nf">parameters</span><span class="p">(</span><span class="bp">self</span><span class="p">):</span>
            <span class="k">return</span> <span class="p">{</span><span class="s">&#39;A&#39;</span><span class="p">:</span> <span class="bp">self</span><span class="o">.</span><span class="n">A</span><span class="p">,</span> <span class="s">&#39;w&#39;</span><span class="p">:</span> <span class="bp">self</span><span class="o">.</span><span class="n">w</span><span class="p">,</span> <span class="s">&#39;x0&#39;</span><span class="p">:</span> <span class="bp">self</span><span class="o">.</span><span class="n">x0</span><span class="p">}</span>


    <span class="k">def</span> <span class="nf">growing_source</span><span class="p">(</span><span class="n">x</span><span class="p">,</span> <span class="n">t</span><span class="p">):</span>
        <span class="n">A</span> <span class="o">=</span> <span class="mi">1</span><span class="p">;</span> <span class="n">w</span>  <span class="o">=</span> <span class="mf">0.1</span><span class="p">;</span> <span class="n">x0</span> <span class="o">=</span> <span class="mi">5</span>
        <span class="k">return</span> <span class="n">A</span><span class="o">*</span><span class="p">(</span><span class="n">sin</span><span class="p">(</span><span class="n">w</span><span class="o">*</span><span class="n">t</span><span class="p">))</span><span class="o">**</span><span class="mi">2</span><span class="o">*</span><span class="n">exp</span><span class="p">(</span><span class="o">-</span><span class="p">(</span><span class="n">x</span><span class="o">-</span><span class="n">x0</span><span class="p">)</span><span class="o">**</span><span class="mi">2</span><span class="p">)</span>

    <span class="k">class</span> <span class="nc">MovingSource2</span><span class="p">:</span>
        <span class="sd">&quot;&quot;&quot;</span>
<span class="sd">        As MovingSource1, but let the user specify</span>
<span class="sd">        (through a drawing, for instance) the spatial shape f:</span>
<span class="sd">        f(x - x0 - sin(w*t)).</span>
<span class="sd">        &quot;&quot;&quot;</span>
        <span class="k">def</span> <span class="nf">__init__</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">w</span><span class="p">,</span> <span class="n">x0</span><span class="p">):</span>
            <span class="bp">self</span><span class="o">.</span><span class="n">w</span> <span class="o">=</span> <span class="n">w</span><span class="p">;</span> <span class="bp">self</span><span class="o">.</span><span class="n">x0</span> <span class="o">=</span> <span class="n">x0</span>
            <span class="bp">self</span><span class="o">.</span><span class="n">spatial_shape</span> <span class="o">=</span> <span class="k">lambda</span> <span class="n">x</span><span class="p">:</span> <span class="n">exp</span><span class="p">(</span><span class="o">-</span><span class="n">x</span><span class="o">*</span><span class="n">x</span><span class="p">)</span>
        <span class="k">def</span> <span class="nf">attach_func</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">spatial_shape</span><span class="p">):</span>
            <span class="bp">self</span><span class="o">.</span><span class="n">spatial_shape</span> <span class="o">=</span> <span class="n">spatial_shape</span>
        <span class="k">def</span> <span class="nf">__call__</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">x</span><span class="p">,</span> <span class="n">t</span><span class="p">):</span>
            <span class="k">return</span> <span class="bp">self</span><span class="o">.</span><span class="n">spatial_shape</span><span class="p">(</span><span class="n">x</span> <span class="o">-</span> <span class="bp">self</span><span class="o">.</span><span class="n">x0</span> <span class="o">-</span> <span class="n">sin</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">w</span><span class="o">*</span><span class="n">t</span><span class="p">))</span>
        <span class="k">def</span> <span class="nf">__str__</span><span class="p">(</span><span class="bp">self</span><span class="p">):</span>
            <span class="k">return</span> <span class="s">&#39;f(x - x0 - sin(w*t))&#39;</span>
        <span class="k">def</span> <span class="nf">parameters</span><span class="p">(</span><span class="bp">self</span><span class="p">):</span>
            <span class="k">return</span> <span class="p">{</span><span class="s">&#39;w&#39;</span><span class="p">:</span> <span class="bp">self</span><span class="o">.</span><span class="n">w</span><span class="p">,</span> <span class="s">&#39;x0&#39;</span><span class="p">:</span> <span class="bp">self</span><span class="o">.</span><span class="n">x0</span><span class="p">}</span>

    <span class="n">ms1</span> <span class="o">=</span> <span class="n">MovingSource1</span><span class="p">(</span><span class="mi">1</span><span class="p">,</span> <span class="mi">1</span><span class="p">,</span> <span class="mi">5</span><span class="p">)</span>
    <span class="n">ms2</span> <span class="o">=</span> <span class="n">MovingSource2</span><span class="p">(</span><span class="mi">1</span><span class="p">,</span> <span class="mi">5</span><span class="p">)</span>

    <span class="n">F</span> <span class="o">=</span> <span class="n">FuncSpec</span>  <span class="c"># short form</span>
    <span class="n">f</span> <span class="o">=</span> <span class="p">[</span><span class="n">F</span><span class="p">(</span><span class="n">UserFunction</span><span class="p">,</span> <span class="n">name</span><span class="o">=</span><span class="s">&#39;moving source 1&#39;</span><span class="p">,</span>
           <span class="n">independent_variables</span><span class="o">=</span><span class="p">(</span><span class="s">&#39;x&#39;</span><span class="p">,</span> <span class="s">&#39;t&#39;</span><span class="p">),</span>
           <span class="n">formula</span><span class="o">=</span><span class="nb">str</span><span class="p">(</span><span class="n">ms1</span><span class="p">),</span>
           <span class="n">function_object</span><span class="o">=</span><span class="n">ms1</span><span class="p">,</span>
           <span class="n">parameters</span><span class="o">=</span><span class="n">ms1</span><span class="o">.</span><span class="n">parameters</span><span class="p">()),</span>
         <span class="n">F</span><span class="p">(</span><span class="n">UserFunction</span><span class="p">,</span> <span class="n">name</span><span class="o">=</span><span class="s">&#39;growing source 1&#39;</span><span class="p">,</span>
           <span class="n">independent_variables</span><span class="o">=</span><span class="p">(</span><span class="s">&#39;x&#39;</span><span class="p">,</span> <span class="s">&#39;t&#39;</span><span class="p">),</span>
           <span class="n">formula</span><span class="o">=</span><span class="s">&#39;A*(sin(w*t))**2*exp(-(x-x0)**2); A=1, w=0.1&#39;</span><span class="p">,</span>
           <span class="n">function_object</span><span class="o">=</span><span class="n">growing_source</span><span class="p">),</span>
         <span class="n">F</span><span class="p">(</span><span class="n">Drawing</span><span class="p">,</span> <span class="n">name</span><span class="o">=</span><span class="s">&#39;moving source 2&#39;</span><span class="p">,</span>
           <span class="n">independent_variables</span><span class="o">=</span><span class="p">(</span><span class="s">&#39;x&#39;</span><span class="p">,</span> <span class="s">&#39;t&#39;</span><span class="p">),</span>
           <span class="n">description</span><span class="o">=</span><span class="s">&#39;spatial shape f(x) can be drawn&#39;</span><span class="p">,</span>
           <span class="n">function_object</span><span class="o">=</span><span class="n">ms2</span><span class="p">,</span>
           <span class="n">parameters</span><span class="o">=</span><span class="n">ms2</span><span class="o">.</span><span class="n">parameters</span><span class="p">(),</span>
           <span class="n">formula</span><span class="o">=</span><span class="nb">str</span><span class="p">(</span><span class="n">ms2</span><span class="p">),</span>
           <span class="n">xcoor</span><span class="o">=</span><span class="n">seq</span><span class="p">(</span><span class="mi">0</span><span class="p">,</span><span class="mi">10</span><span class="p">,</span><span class="mf">0.1</span><span class="p">),),</span>
         <span class="n">F</span><span class="p">(</span><span class="n">StringFormula</span><span class="p">,</span> <span class="n">name</span><span class="o">=</span><span class="s">&#39;growing source 2&#39;</span><span class="p">,</span>
           <span class="n">parameters</span><span class="o">=</span><span class="p">{</span><span class="s">&#39;A&#39;</span><span class="p">:</span> <span class="mf">1.0</span><span class="p">,</span> <span class="s">&#39;w&#39;</span><span class="p">:</span> <span class="mf">1.0</span><span class="p">,</span> <span class="s">&#39;x0&#39;</span><span class="p">:</span> <span class="mi">0</span><span class="p">},</span>
           <span class="n">formula</span><span class="o">=</span><span class="s">&#39;A*(sin(w*t))**2*exp(-(x-x0)**2)&#39;</span><span class="p">,</span>
           <span class="n">independent_variables</span><span class="o">=</span><span class="p">(</span><span class="s">&#39;x&#39;</span><span class="p">,</span> <span class="s">&#39;t&#39;</span><span class="p">)),</span>
         <span class="n">F</span><span class="p">(</span><span class="n">UserFunction</span><span class="p">,</span> <span class="n">name</span><span class="o">=</span><span class="s">&#39;no source&#39;</span><span class="p">,</span>
           <span class="n">independent_variables</span><span class="o">=</span><span class="p">(</span><span class="s">&#39;x&#39;</span><span class="p">,</span> <span class="s">&#39;t&#39;</span><span class="p">),</span>
           <span class="n">formula</span><span class="o">=</span><span class="s">&#39;f(x,t)=0&#39;</span><span class="p">,</span>
           <span class="n">function_object</span><span class="o">=</span><span class="k">lambda</span> <span class="n">x</span><span class="p">,</span><span class="n">t</span><span class="p">:</span> <span class="mi">0</span><span class="p">),</span>
         <span class="p">]</span>
    <span class="n">s</span><span class="o">.</span><span class="n">add</span><span class="p">(</span><span class="s">&#39;f&#39;</span><span class="p">,</span> <span class="n">f</span><span class="p">)</span>

    <span class="k">class</span> <span class="nc">GaussianBell</span><span class="p">:</span>
        <span class="sd">&quot;&quot;&quot;Gaussian Bell at x0 with st.dev. sigma.&quot;&quot;&quot;</span>
        <span class="k">def</span> <span class="nf">__init__</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">x0</span><span class="p">,</span> <span class="n">sigma</span><span class="p">):</span>
            <span class="bp">self</span><span class="o">.</span><span class="n">x0</span> <span class="o">=</span> <span class="n">x0</span><span class="p">;</span> <span class="bp">self</span><span class="o">.</span><span class="n">sigma</span> <span class="o">=</span> <span class="n">sigma</span>
        <span class="k">def</span> <span class="nf">__call__</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">x</span><span class="p">):</span>
            <span class="k">return</span> <span class="n">exp</span><span class="p">(</span><span class="o">-</span><span class="mf">0.5</span><span class="o">*</span><span class="p">((</span><span class="n">x</span><span class="o">-</span><span class="bp">self</span><span class="o">.</span><span class="n">x0</span><span class="p">)</span><span class="o">/</span><span class="bp">self</span><span class="o">.</span><span class="n">sigma</span><span class="p">)</span><span class="o">**</span><span class="mi">2</span><span class="p">)</span>
        <span class="k">def</span> <span class="nf">__str__</span><span class="p">(</span><span class="bp">self</span><span class="p">):</span>
            <span class="k">return</span> <span class="s">&#39;exp(-0.5*((x-x0)/sigma)**2)&#39;</span>
        <span class="k">def</span> <span class="nf">parameters</span><span class="p">(</span><span class="bp">self</span><span class="p">):</span>
            <span class="k">return</span> <span class="p">{</span><span class="s">&#39;x0&#39;</span><span class="p">:</span> <span class="bp">self</span><span class="o">.</span><span class="n">x0</span><span class="p">,</span> <span class="s">&#39;sigma&#39;</span><span class="p">:</span> <span class="bp">self</span><span class="o">.</span><span class="n">sigma</span><span class="p">}</span>

    <span class="n">gb</span> <span class="o">=</span> <span class="n">GaussianBell</span><span class="p">(</span><span class="mi">5</span><span class="p">,</span><span class="mi">1</span><span class="p">)</span>
    <span class="n">I</span> <span class="o">=</span> <span class="p">[</span><span class="n">F</span><span class="p">(</span><span class="n">UserFunction</span><span class="p">,</span> <span class="n">name</span><span class="o">=</span><span class="s">&#39;localized disturbance&#39;</span><span class="p">,</span>
           <span class="n">function_object</span><span class="o">=</span><span class="n">gb</span><span class="p">,</span>
           <span class="n">independent_variables</span><span class="o">=</span><span class="p">[</span><span class="s">&#39;x&#39;</span><span class="p">],</span>
           <span class="n">parameters</span><span class="o">=</span><span class="n">gb</span><span class="o">.</span><span class="n">parameters</span><span class="p">()),</span>
         <span class="n">F</span><span class="p">(</span><span class="n">Drawing</span><span class="p">,</span> <span class="n">name</span><span class="o">=</span><span class="s">&#39;draw initial shape&#39;</span><span class="p">,</span>
           <span class="n">independent_variables</span><span class="o">=</span><span class="p">[</span><span class="s">&#39;x&#39;</span><span class="p">],</span>
           <span class="n">xcoor</span><span class="o">=</span><span class="n">seq</span><span class="p">(</span><span class="mi">0</span><span class="p">,</span><span class="mi">10</span><span class="p">,</span><span class="mf">0.1</span><span class="p">),)</span>
         <span class="p">]</span>
    <span class="n">s</span><span class="o">.</span><span class="n">add</span><span class="p">(</span><span class="s">&#39;initial condition&#39;</span><span class="p">,</span> <span class="n">I</span><span class="p">)</span>

    <span class="k">class</span> <span class="nc">OscHalfPeriod</span><span class="p">:</span>
        <span class="sd">&quot;&quot;&quot;Oscillate sin(w*t) half a period, then hold zero.&quot;&quot;&quot;</span>
        <span class="k">def</span> <span class="nf">__init__</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">w</span><span class="p">):</span>
            <span class="bp">self</span><span class="o">.</span><span class="n">w</span> <span class="o">=</span> <span class="n">w</span>
        <span class="k">def</span> <span class="nf">__call__</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">t</span><span class="p">):</span>
            <span class="n">T</span> <span class="o">=</span> <span class="n">pi</span><span class="o">/</span><span class="bp">self</span><span class="o">.</span><span class="n">w</span>
            <span class="k">if</span> <span class="n">t</span> <span class="o">&lt;=</span> <span class="n">T</span><span class="p">:</span>
                <span class="k">return</span> <span class="n">sin</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">w</span><span class="o">*</span><span class="n">t</span><span class="p">)</span>
            <span class="k">else</span><span class="p">:</span>
                <span class="k">return</span> <span class="mf">0.0</span>
        <span class="k">def</span> <span class="nf">__str__</span><span class="p">(</span><span class="bp">self</span><span class="p">):</span>
            <span class="k">return</span> <span class="s">&#39;sin(w*t) for t&lt;pi/w, otherwise 0&#39;</span>
        <span class="k">def</span> <span class="nf">parameters</span><span class="p">(</span><span class="bp">self</span><span class="p">):</span>
            <span class="k">return</span> <span class="p">{</span><span class="s">&#39;w&#39;</span><span class="p">:</span> <span class="bp">self</span><span class="o">.</span><span class="n">w</span><span class="p">}</span>

    <span class="n">half_period</span> <span class="o">=</span> <span class="n">OscHalfPeriod</span><span class="p">(</span><span class="n">pi</span><span class="o">/</span><span class="mi">2</span><span class="p">)</span>
    <span class="n">bc</span> <span class="o">=</span> <span class="p">[</span><span class="n">F</span><span class="p">(</span><span class="n">UserFunction</span><span class="p">,</span> <span class="n">name</span><span class="o">=</span><span class="s">&#39;1 period oscillation&#39;</span><span class="p">,</span>
            <span class="n">independent_variables</span><span class="o">=</span><span class="p">(</span><span class="s">&#39;t&#39;</span><span class="p">,),</span>
            <span class="n">function_object</span><span class="o">=</span><span class="n">half_period</span><span class="p">,</span>
            <span class="n">formula</span><span class="o">=</span><span class="nb">str</span><span class="p">(</span><span class="n">half_period</span><span class="p">),</span>
            <span class="n">parameters</span><span class="o">=</span><span class="n">half_period</span><span class="o">.</span><span class="n">parameters</span><span class="p">()),</span>
          <span class="n">F</span><span class="p">(</span><span class="n">UserFunction</span><span class="p">,</span> <span class="n">name</span><span class="o">=</span><span class="s">&#39;fixed ends&#39;</span><span class="p">,</span>
            <span class="n">independent_variables</span><span class="o">=</span><span class="p">(</span><span class="s">&#39;t&#39;</span><span class="p">,),</span>
            <span class="n">function_object</span><span class="o">=</span><span class="k">lambda</span> <span class="n">x</span><span class="p">:</span> <span class="mi">0</span><span class="p">,</span>
            <span class="n">formula</span><span class="o">=</span><span class="s">&#39;u=0 at the ends&#39;</span><span class="p">,),</span>
          <span class="p">]</span>
    <span class="n">s</span><span class="o">.</span><span class="n">add</span><span class="p">(</span><span class="s">&#39;boundary conditions&#39;</span><span class="p">,</span> <span class="n">bc</span><span class="p">)</span>
    <span class="n">s</span><span class="o">.</span><span class="n">pack</span><span class="p">()</span>

    <span class="k">def</span> <span class="nf">get</span><span class="p">():</span>
        <span class="n">f_func</span><span class="p">,</span> <span class="n">page</span> <span class="o">=</span> <span class="n">s</span><span class="o">.</span><span class="n">get</span><span class="p">(</span><span class="s">&#39;f&#39;</span><span class="p">)</span>
        <span class="n">I_func</span><span class="p">,</span> <span class="n">page</span> <span class="o">=</span> <span class="n">s</span><span class="o">.</span><span class="n">get</span><span class="p">(</span><span class="s">&#39;initial condition&#39;</span><span class="p">)</span>
        <span class="n">bc_func</span><span class="p">,</span> <span class="n">page</span> <span class="o">=</span> <span class="n">s</span><span class="o">.</span><span class="n">get</span><span class="p">(</span><span class="s">&#39;boundary conditions&#39;</span><span class="p">)</span>
        <span class="kn">from</span> <span class="nn">scitools.misc</span> <span class="kn">import</span> <span class="n">dump</span>
        <span class="k">print</span> <span class="s">&#39;f_func:&#39;</span>
        <span class="n">dump</span><span class="p">(</span><span class="n">f_func</span><span class="p">,</span> <span class="n">hide_nonpublic</span><span class="o">=</span><span class="bp">False</span><span class="p">)</span>
        <span class="k">print</span> <span class="s">&#39;I_func:&#39;</span>
        <span class="n">dump</span><span class="p">(</span><span class="n">I_func</span><span class="p">,</span> <span class="n">hide_nonpublic</span><span class="o">=</span><span class="bp">False</span><span class="p">)</span>
        <span class="k">print</span> <span class="s">&#39;bc_func:&#39;</span>
        <span class="n">dump</span><span class="p">(</span><span class="n">bc_func</span><span class="p">,</span> <span class="n">hide_nonpublic</span><span class="o">=</span><span class="bp">False</span><span class="p">)</span>

    <span class="n">Tkinter</span><span class="o">.</span><span class="n">Button</span><span class="p">(</span><span class="n">root</span><span class="p">,</span> <span class="n">text</span><span class="o">=</span><span class="s">&#39;get&#39;</span><span class="p">,</span>
                   <span class="n">command</span><span class="o">=</span><span class="n">get</span><span class="p">)</span><span class="o">.</span><span class="n">pack</span><span class="p">(</span><span class="n">pady</span><span class="o">=</span><span class="mi">5</span><span class="p">)</span>
    <span class="n">root</span><span class="o">.</span><span class="n">mainloop</span><span class="p">()</span>


<span class="k">def</span> <span class="nf">_FunctionSelector_test</span><span class="p">():</span>
    <span class="n">root</span> <span class="o">=</span> <span class="n">Tkinter</span><span class="o">.</span><span class="n">Tk</span><span class="p">()</span>
    <span class="n">Pmw</span><span class="o">.</span><span class="n">initialise</span><span class="p">(</span><span class="n">root</span><span class="p">)</span>
    <span class="kn">import</span> <span class="nn">scitools.misc</span>
    <span class="n">scitools</span><span class="o">.</span><span class="n">misc</span><span class="o">.</span><span class="n">fontscheme6</span><span class="p">(</span><span class="n">root</span><span class="p">)</span>
    <span class="n">root</span><span class="o">.</span><span class="n">title</span><span class="p">(</span><span class="s">&#39;FunctionSelector notebook demo&#39;</span><span class="p">)</span>
    <span class="n">_test_FunctionSelector</span><span class="p">(</span><span class="n">root</span><span class="p">)</span>



<div class="viewcode-block" id="FuncDependenceViz"><a class="viewcode-back" href="../../TkGUI.html#scitools.TkGUI.FuncDependenceViz">[docs]</a><span class="k">class</span> <span class="nc">FuncDependenceViz</span><span class="p">:</span>
    <span class="sd">&quot;&quot;&quot;</span>
<span class="sd">    Visualization of the shape of a function depends</span>
<span class="sd">    continuously on its parameters, and this class</span>
<span class="sd">    makes a graphical illustration of this dependence.</span>

<span class="sd">    &quot;&quot;&quot;</span>
<div class="viewcode-block" id="FuncDependenceViz.__init__"><a class="viewcode-back" href="../../TkGUI.html#scitools.TkGUI.FuncDependenceViz.__init__">[docs]</a>    <span class="k">def</span> <span class="nf">__init__</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">master</span><span class="p">,</span>
                 <span class="n">parameter_intervals</span><span class="o">=</span><span class="p">{},</span> <span class="c"># interval for each prm</span>
                 <span class="n">functions</span><span class="o">=</span><span class="p">{},</span>           <span class="c"># functions to be plotted</span>
                 <span class="n">xmin</span><span class="o">=</span><span class="mf">0.0</span><span class="p">,</span> <span class="n">xmax</span><span class="o">=</span><span class="mf">1.0</span><span class="p">,</span>     <span class="c"># x axis range</span>
                 <span class="n">resolution</span><span class="o">=</span><span class="mi">101</span><span class="p">,</span>         <span class="c"># no of x evaluations</span>
                 <span class="n">width</span><span class="o">=</span><span class="mi">500</span><span class="p">,</span> <span class="n">height</span><span class="o">=</span><span class="mi">400</span><span class="p">,</span>  <span class="c"># size of plot window</span>
                 <span class="n">viztool</span> <span class="o">=</span> <span class="s">&#39;Pmw.Blt.Graph&#39;</span><span class="p">,</span> <span class="c"># or &#39;gnuplot&#39;</span>
                 <span class="n">plot_update</span> <span class="o">=</span> <span class="s">&#39;after&#39;</span>   <span class="c"># how slider movements</span>
                                         <span class="c"># update the plots</span>
                 <span class="p">):</span>
        <span class="sd">&quot;&quot;&quot;</span>
<span class="sd">        Define a set of functions depending on a set of parameters.</span>
<span class="sd">        This class creates a GUI where the parameters can be adjusted,</span>
<span class="sd">        and the effect on the function graphs can be seen immediately.</span>
<span class="sd">        &quot;&quot;&quot;</span>
        <span class="kn">import</span> <span class="nn">scitools.modulecheck</span> <span class="kn">as</span> <span class="nn">sm</span>
        <span class="n">sm</span><span class="p">(</span><span class="s">&quot;TkGUI module:&quot;</span><span class="p">,</span> <span class="s">&#39;Pmw&#39;</span><span class="p">,</span> <span class="s">&#39;Tkinter&#39;</span><span class="p">,</span> <span class="s">&#39;Gnuplot&#39;</span><span class="p">,</span> <span class="s">&#39;numpy&#39;</span><span class="p">)</span>

        <span class="n">Gnuplot</span> <span class="o">=</span> <span class="n">import_module</span><span class="p">(</span><span class="s">&#39;Gnuplot&#39;</span><span class="p">)</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">Gnuplot</span> <span class="o">=</span> <span class="n">Gnuplot</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">master</span> <span class="o">=</span> <span class="n">master</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">top</span> <span class="o">=</span> <span class="n">Tkinter</span><span class="o">.</span><span class="n">Frame</span><span class="p">(</span><span class="n">master</span><span class="p">,</span> <span class="n">borderwidth</span><span class="o">=</span><span class="mi">2</span><span class="p">)</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">top</span><span class="o">.</span><span class="n">pack</span><span class="p">()</span>  <span class="c"># could leave this pack for a pack class function</span>

        <span class="bp">self</span><span class="o">.</span><span class="n">p_intervals</span> <span class="o">=</span> <span class="n">parameter_intervals</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">funcs</span> <span class="o">=</span> <span class="n">functions</span>  <span class="c"># f_i(x; p_1,...p_n)</span>

        <span class="bp">self</span><span class="o">.</span><span class="n">p</span> <span class="o">=</span> <span class="p">{}</span>           <span class="c"># values of the parameters</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">slider_var</span> <span class="o">=</span> <span class="p">{}</span>  <span class="c"># Tkinter vars for slide.p</span>
        <span class="k">for</span> <span class="n">pname</span> <span class="ow">in</span> <span class="bp">self</span><span class="o">.</span><span class="n">p_intervals</span><span class="p">:</span>
            <span class="c"># set parameter value to midpoint in interval:</span>
            <span class="bp">self</span><span class="o">.</span><span class="n">p</span><span class="p">[</span><span class="n">pname</span><span class="p">]</span> <span class="o">=</span> <span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">p_intervals</span><span class="p">[</span><span class="n">pname</span><span class="p">][</span><span class="mi">0</span><span class="p">]</span> <span class="o">+</span> \
                             <span class="bp">self</span><span class="o">.</span><span class="n">p_intervals</span><span class="p">[</span><span class="n">pname</span><span class="p">][</span><span class="mi">1</span><span class="p">])</span><span class="o">/</span><span class="mf">2.0</span>
            <span class="bp">self</span><span class="o">.</span><span class="n">slider_var</span><span class="p">[</span><span class="n">pname</span><span class="p">]</span> <span class="o">=</span> <span class="n">Tkinter</span><span class="o">.</span><span class="n">DoubleVar</span><span class="p">()</span>
            <span class="bp">self</span><span class="o">.</span><span class="n">slider_var</span><span class="p">[</span><span class="n">pname</span><span class="p">]</span><span class="o">.</span><span class="n">set</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">p</span><span class="p">[</span><span class="n">pname</span><span class="p">])</span>

        <span class="c"># define the sliders:</span>
        <span class="k">for</span> <span class="n">pname</span> <span class="ow">in</span> <span class="bp">self</span><span class="o">.</span><span class="n">p_intervals</span><span class="p">:</span>
            <span class="n">pmin</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">p_intervals</span><span class="p">[</span><span class="n">pname</span><span class="p">][</span><span class="mi">0</span><span class="p">]</span>
            <span class="n">pmax</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">p_intervals</span><span class="p">[</span><span class="n">pname</span><span class="p">][</span><span class="mi">1</span><span class="p">]</span>
            <span class="n">slider</span> <span class="o">=</span> <span class="n">Tkinter</span><span class="o">.</span><span class="n">Scale</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">top</span><span class="p">,</span>
                           <span class="n">orient</span><span class="o">=</span><span class="s">&#39;horizontal&#39;</span><span class="p">,</span>
                           <span class="n">from_</span><span class="o">=</span><span class="n">pmin</span><span class="p">,</span>
                           <span class="n">to</span><span class="o">=</span><span class="n">pmax</span><span class="p">,</span>
                           <span class="n">tickinterval</span><span class="o">=</span><span class="p">(</span><span class="n">pmax</span><span class="o">-</span><span class="n">pmin</span><span class="p">)</span><span class="o">/</span><span class="mf">10.0</span><span class="p">,</span>
                           <span class="n">resolution</span><span class="o">=</span><span class="p">(</span><span class="n">pmax</span><span class="o">-</span><span class="n">pmin</span><span class="p">)</span><span class="o">/</span><span class="mf">100.0</span><span class="p">,</span>
                           <span class="n">label</span><span class="o">=</span><span class="n">pname</span><span class="p">,</span>
                           <span class="n">font</span><span class="o">=</span><span class="s">&quot;helvetica 10 bold&quot;</span><span class="p">,</span>
                           <span class="n">length</span><span class="o">=</span><span class="n">width</span><span class="o">-</span><span class="mi">100</span><span class="p">,</span>
                           <span class="n">variable</span><span class="o">=</span><span class="bp">self</span><span class="o">.</span><span class="n">slider_var</span><span class="p">[</span><span class="n">pname</span><span class="p">])</span>
            <span class="n">slider</span><span class="o">.</span><span class="n">pack</span><span class="p">(</span><span class="n">side</span><span class="o">=</span><span class="s">&#39;top&#39;</span><span class="p">,</span> <span class="n">pady</span><span class="o">=</span><span class="mi">4</span><span class="p">)</span>

            <span class="c"># we can update the plot according to slider</span>
            <span class="c"># movements in two ways: during movement</span>
            <span class="c"># (command= option) or after movement (event binding)</span>
            <span class="k">if</span> <span class="n">plot_update</span> <span class="o">==</span> <span class="s">&#39;after&#39;</span><span class="p">:</span>
                <span class="n">slider</span><span class="o">.</span><span class="n">bind</span><span class="p">(</span><span class="s">&#39;&lt;ButtonRelease-1&gt;&#39;</span><span class="p">,</span> <span class="bp">self</span><span class="o">.</span><span class="n">visualize</span><span class="p">)</span>
            <span class="k">else</span><span class="p">:</span>
                <span class="n">slider</span><span class="o">.</span><span class="n">configure</span><span class="p">(</span><span class="n">command</span><span class="o">=</span><span class="bp">self</span><span class="o">.</span><span class="n">visualize</span><span class="p">)</span>
            <span class="c"># does not work: slider.bind(&#39;&lt;B1-Motion&gt;&#39;, self.visualize)</span>

        <span class="c"># define a widget row where xmin/xmax and n can be adjusted:</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">xmin</span> <span class="o">=</span> <span class="n">Tkinter</span><span class="o">.</span><span class="n">DoubleVar</span><span class="p">();</span> <span class="bp">self</span><span class="o">.</span><span class="n">xmin</span><span class="o">.</span><span class="n">set</span><span class="p">(</span><span class="n">xmin</span><span class="p">)</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">xmax</span> <span class="o">=</span> <span class="n">Tkinter</span><span class="o">.</span><span class="n">DoubleVar</span><span class="p">();</span> <span class="bp">self</span><span class="o">.</span><span class="n">xmax</span><span class="o">.</span><span class="n">set</span><span class="p">(</span><span class="n">xmax</span><span class="p">)</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">n</span> <span class="o">=</span> <span class="n">Tkinter</span><span class="o">.</span><span class="n">IntVar</span><span class="p">();</span> <span class="bp">self</span><span class="o">.</span><span class="n">n</span><span class="o">.</span><span class="n">set</span><span class="p">(</span><span class="n">resolution</span><span class="p">)</span>

        <span class="n">row</span> <span class="o">=</span> <span class="n">Tkinter</span><span class="o">.</span><span class="n">Frame</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">top</span><span class="p">,</span> <span class="n">borderwidth</span><span class="o">=</span><span class="mi">2</span><span class="p">)</span>
        <span class="n">row</span><span class="o">.</span><span class="n">pack</span><span class="p">()</span>
        <span class="n">Tkinter</span><span class="o">.</span><span class="n">Label</span><span class="p">(</span><span class="n">row</span><span class="p">,</span> <span class="n">text</span><span class="o">=</span><span class="s">&quot;x min:&quot;</span><span class="p">)</span><span class="o">.</span><span class="n">pack</span><span class="p">(</span><span class="n">side</span><span class="o">=</span><span class="s">&#39;left&#39;</span><span class="p">)</span>
        <span class="n">Tkinter</span><span class="o">.</span><span class="n">Entry</span><span class="p">(</span><span class="n">row</span><span class="p">,</span> <span class="n">textvariable</span><span class="o">=</span><span class="bp">self</span><span class="o">.</span><span class="n">xmin</span><span class="p">,</span> <span class="n">width</span><span class="o">=</span><span class="mi">5</span><span class="p">,</span>
                      <span class="n">justify</span><span class="o">=</span><span class="s">&#39;right&#39;</span><span class="p">)</span><span class="o">.</span><span class="n">pack</span><span class="p">(</span><span class="n">side</span><span class="o">=</span><span class="s">&#39;left&#39;</span><span class="p">)</span>
        <span class="n">Tkinter</span><span class="o">.</span><span class="n">Label</span><span class="p">(</span><span class="n">row</span><span class="p">,</span> <span class="n">text</span><span class="o">=</span><span class="s">&quot;  x max:&quot;</span><span class="p">)</span><span class="o">.</span><span class="n">pack</span><span class="p">(</span><span class="n">side</span><span class="o">=</span><span class="s">&#39;left&#39;</span><span class="p">)</span>
        <span class="n">Tkinter</span><span class="o">.</span><span class="n">Entry</span><span class="p">(</span><span class="n">row</span><span class="p">,</span> <span class="n">textvariable</span><span class="o">=</span><span class="bp">self</span><span class="o">.</span><span class="n">xmax</span><span class="p">,</span> <span class="n">width</span><span class="o">=</span><span class="mi">5</span><span class="p">,</span>
                      <span class="n">justify</span><span class="o">=</span><span class="s">&#39;right&#39;</span><span class="p">)</span><span class="o">.</span><span class="n">pack</span><span class="p">(</span><span class="n">side</span><span class="o">=</span><span class="s">&#39;left&#39;</span><span class="p">)</span>
        <span class="n">Tkinter</span><span class="o">.</span><span class="n">Label</span><span class="p">(</span><span class="n">row</span><span class="p">,</span> <span class="n">text</span><span class="o">=</span><span class="s">&quot;  no of points:&quot;</span><span class="p">)</span><span class="o">.</span><span class="n">pack</span><span class="p">(</span><span class="n">side</span><span class="o">=</span><span class="s">&#39;left&#39;</span><span class="p">)</span>
        <span class="n">Tkinter</span><span class="o">.</span><span class="n">Entry</span><span class="p">(</span><span class="n">row</span><span class="p">,</span> <span class="n">textvariable</span><span class="o">=</span><span class="bp">self</span><span class="o">.</span><span class="n">n</span><span class="p">,</span> <span class="n">width</span><span class="o">=</span><span class="mi">3</span><span class="p">,</span>
                      <span class="n">justify</span><span class="o">=</span><span class="s">&#39;right&#39;</span><span class="p">)</span><span class="o">.</span><span class="n">pack</span><span class="p">(</span><span class="n">side</span><span class="o">=</span><span class="s">&#39;left&#39;</span><span class="p">)</span>

        <span class="c"># make graph widget or use a plotting program?</span>
        <span class="k">try</span><span class="p">:</span>
            <span class="c"># see if we can create a BLT graph successfully:</span>
            <span class="bp">self</span><span class="o">.</span><span class="n">g</span> <span class="o">=</span> <span class="n">Pmw</span><span class="o">.</span><span class="n">Blt</span><span class="o">.</span><span class="n">Graph</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">top</span><span class="p">,</span>
                                   <span class="n">width</span><span class="o">=</span><span class="n">width</span><span class="p">,</span> <span class="n">height</span><span class="o">=</span><span class="n">height</span><span class="p">)</span>
            <span class="n">have_blt</span> <span class="o">=</span> <span class="mi">1</span>
        <span class="k">except</span><span class="p">:</span>
            <span class="n">have_blt</span> <span class="o">=</span> <span class="mi">0</span>

        <span class="bp">self</span><span class="o">.</span><span class="n">viztool</span> <span class="o">=</span> <span class="n">viztool</span>  <span class="c"># user-specified plotting tool</span>

        <span class="k">print</span> <span class="n">have_blt</span><span class="p">,</span> <span class="n">viztool</span>
        <span class="k">if</span> <span class="n">have_blt</span> <span class="ow">and</span> <span class="n">viztool</span> <span class="o">==</span> <span class="s">&quot;Pmw.Blt.Graph&quot;</span><span class="p">:</span>
            <span class="bp">self</span><span class="o">.</span><span class="n">g</span><span class="o">.</span><span class="n">pack</span><span class="p">(</span><span class="n">expand</span><span class="o">=</span><span class="mi">1</span><span class="p">,</span> <span class="n">fill</span><span class="o">=</span><span class="s">&#39;both&#39;</span><span class="p">)</span>
        <span class="k">else</span><span class="p">:</span>
            <span class="c"># we do not have BLT or the user has not requested BLT:</span>
            <span class="bp">self</span><span class="o">.</span><span class="n">g</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">Gnuplot</span><span class="o">.</span><span class="n">Gnuplot</span><span class="p">(</span><span class="n">persist</span><span class="o">=</span><span class="mi">1</span><span class="p">)</span>

        <span class="bp">self</span><span class="o">.</span><span class="n">dx</span> <span class="o">=</span> <span class="mi">0</span>  <span class="c"># new vectors must be made if the x incr. changes</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">make_vectors</span><span class="p">()</span>  <span class="c"># vectors for x and y values in plot</span>

        <span class="c"># PostScript plot:</span>
        <span class="n">Tkinter</span><span class="o">.</span><span class="n">Button</span><span class="p">(</span><span class="n">row</span><span class="p">,</span> <span class="n">text</span><span class="o">=</span><span class="s">&quot;Postscript plot&quot;</span><span class="p">,</span>
                       <span class="n">command</span><span class="o">=</span><span class="bp">self</span><span class="o">.</span><span class="n">psdump</span><span class="p">)</span><span class="o">.</span><span class="n">pack</span><span class="p">(</span><span class="n">side</span><span class="o">=</span><span class="s">&#39;left&#39;</span><span class="p">,</span><span class="n">padx</span><span class="o">=</span><span class="mi">5</span><span class="p">)</span>
        <span class="c"># bind &#39;p&#39; to dumping the plot in PostScript:</span>
        <span class="c"># (must bind to master, not self.top)</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">master</span><span class="o">.</span><span class="n">bind</span><span class="p">(</span><span class="s">&#39;&lt;p&gt;&#39;</span><span class="p">,</span> <span class="bp">self</span><span class="o">.</span><span class="n">psdump</span><span class="p">)</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">master</span><span class="o">.</span><span class="n">bind</span><span class="p">(</span><span class="s">&#39;&lt;q&gt;&#39;</span><span class="p">,</span> <span class="bp">self</span><span class="o">.</span><span class="n">quit</span><span class="p">)</span>  <span class="c"># convenient</span>
</div>
<div class="viewcode-block" id="FuncDependenceViz.psdump"><a class="viewcode-back" href="../../TkGUI.html#scitools.TkGUI.FuncDependenceViz.psdump">[docs]</a>    <span class="k">def</span> <span class="nf">psdump</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">event</span><span class="o">=</span><span class="bp">None</span><span class="p">):</span>
        <span class="kn">import</span> <span class="nn">tkFileDialog</span>
        <span class="n">fname</span> <span class="o">=</span> <span class="n">tkFileDialog</span><span class="o">.</span><span class="n">SaveAs</span><span class="p">(</span>
                <span class="n">filetypes</span><span class="o">=</span><span class="p">[(</span><span class="s">&#39;psfiles&#39;</span><span class="p">,</span><span class="s">&#39;*.ps&#39;</span><span class="p">)],</span>
                <span class="n">initialfile</span><span class="o">=</span><span class="s">&quot;tmp.ps&quot;</span><span class="p">,</span>
                <span class="n">title</span><span class="o">=</span><span class="s">&quot;Save plot in PostScript format&quot;</span><span class="p">)</span><span class="o">.</span><span class="n">show</span><span class="p">()</span>
        <span class="k">if</span> <span class="n">fname</span><span class="p">:</span>
            <span class="k">if</span> <span class="bp">self</span><span class="o">.</span><span class="n">viztool</span> <span class="o">==</span> <span class="s">&quot;gnuplot&quot;</span><span class="p">:</span>
                <span class="bp">self</span><span class="o">.</span><span class="n">g</span><span class="o">.</span><span class="n">hardcopy</span><span class="p">(</span><span class="n">filename</span><span class="o">=</span><span class="n">fname</span><span class="p">,</span> <span class="n">enhanced</span><span class="o">=</span><span class="mi">1</span><span class="p">,</span>
                                <span class="n">mode</span><span class="o">=</span><span class="s">&#39;eps&#39;</span><span class="p">,</span> <span class="n">color</span><span class="o">=</span><span class="mi">0</span><span class="p">,</span>
                                <span class="n">fontname</span><span class="o">=</span><span class="s">&#39;Times-Roman&#39;</span><span class="p">,</span> <span class="n">fontsize</span><span class="o">=</span><span class="mi">28</span><span class="p">)</span>
            <span class="k">elif</span> <span class="bp">self</span><span class="o">.</span><span class="n">viztool</span> <span class="o">==</span> <span class="s">&quot;Pmw.Blt.Graph&quot;</span><span class="p">:</span>
                <span class="bp">self</span><span class="o">.</span><span class="n">g</span><span class="o">.</span><span class="n">postscript_output</span><span class="p">(</span><span class="n">fileName</span><span class="o">=</span><span class="n">fname</span><span class="p">,</span>
                                         <span class="n">decorations</span><span class="o">=</span><span class="s">&#39;no&#39;</span><span class="p">)</span>
</div>
<div class="viewcode-block" id="FuncDependenceViz.quit"><a class="viewcode-back" href="../../TkGUI.html#scitools.TkGUI.FuncDependenceViz.quit">[docs]</a>    <span class="k">def</span> <span class="nf">quit</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">event</span><span class="o">=</span><span class="bp">None</span><span class="p">):</span>
        <span class="s">&quot;kill plot window&quot;</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">master</span><span class="o">.</span><span class="n">destroy</span><span class="p">()</span>
</div>
<div class="viewcode-block" id="FuncDependenceViz.make_vectors"><a class="viewcode-back" href="../../TkGUI.html#scitools.TkGUI.FuncDependenceViz.make_vectors">[docs]</a>    <span class="k">def</span> <span class="nf">make_vectors</span><span class="p">(</span><span class="bp">self</span><span class="p">):</span>
        <span class="s">&quot;make x vector and a dictionary of y vectors&quot;</span>
        <span class="c"># self.x : vector of x coordinates</span>
        <span class="c"># self.y[funcname] : vector of function values</span>

        <span class="n">dx</span> <span class="o">=</span> <span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">xmax</span><span class="o">.</span><span class="n">get</span><span class="p">()</span> <span class="o">-</span> <span class="bp">self</span><span class="o">.</span><span class="n">xmin</span><span class="o">.</span><span class="n">get</span><span class="p">())</span><span class="o">/</span>\
             <span class="nb">float</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">n</span><span class="o">.</span><span class="n">get</span><span class="p">()</span> <span class="o">-</span> <span class="mi">1</span><span class="p">)</span>
        <span class="k">if</span> <span class="n">dx</span> <span class="o">!=</span> <span class="bp">self</span><span class="o">.</span><span class="n">dx</span><span class="p">:</span>
            <span class="bp">self</span><span class="o">.</span><span class="n">dx</span> <span class="o">=</span> <span class="n">dx</span>
            <span class="c"># x increment has changed, make new vectors:</span>

            <span class="c"># add dx/2 to upper limit to ensure self.n entries:</span>
            <span class="n">x</span> <span class="o">=</span> <span class="n">arange</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">xmin</span><span class="o">.</span><span class="n">get</span><span class="p">(),</span> <span class="bp">self</span><span class="o">.</span><span class="n">xmax</span><span class="o">.</span><span class="n">get</span><span class="p">()</span><span class="o">+</span><span class="n">dx</span><span class="o">/</span><span class="mi">2</span><span class="p">,</span> <span class="n">dx</span><span class="p">,</span> <span class="nb">float</span><span class="p">)</span>
            <span class="k">if</span> <span class="n">x</span><span class="o">.</span><span class="n">shape</span><span class="p">[</span><span class="mi">0</span><span class="p">]</span> <span class="o">!=</span> <span class="bp">self</span><span class="o">.</span><span class="n">n</span><span class="o">.</span><span class="n">get</span><span class="p">():</span>
                <span class="k">raise</span> <span class="ne">IndexError</span><span class="p">(</span><span class="s">&quot;x has wrong length&quot;</span><span class="p">)</span>
            <span class="bp">self</span><span class="o">.</span><span class="n">x</span> <span class="o">=</span> <span class="n">x</span>

            <span class="bp">self</span><span class="o">.</span><span class="n">y</span> <span class="o">=</span> <span class="p">{}</span>
            <span class="k">for</span> <span class="n">funcname</span> <span class="ow">in</span> <span class="bp">self</span><span class="o">.</span><span class="n">funcs</span><span class="p">:</span>
                <span class="bp">self</span><span class="o">.</span><span class="n">y</span><span class="p">[</span><span class="n">funcname</span><span class="p">]</span> <span class="o">=</span> <span class="n">zeros</span><span class="p">(</span><span class="n">x</span><span class="o">.</span><span class="n">shape</span><span class="p">[</span><span class="mi">0</span><span class="p">],</span><span class="nb">float</span><span class="p">)</span>

            <span class="k">if</span> <span class="bp">self</span><span class="o">.</span><span class="n">viztool</span> <span class="o">==</span> <span class="s">&quot;Pmw.Blt.Graph&quot;</span><span class="p">:</span>
                <span class="bp">self</span><span class="o">.</span><span class="n">bind_vectors2BLTgraph</span><span class="p">()</span>

            <span class="c"># fill the vectors with appropriate data for testing:</span>
            <span class="bp">self</span><span class="o">.</span><span class="n">fill_vectors</span><span class="p">()</span>

</div>
<div class="viewcode-block" id="FuncDependenceViz.bind_vectors2BLTgraph"><a class="viewcode-back" href="../../TkGUI.html#scitools.TkGUI.FuncDependenceViz.bind_vectors2BLTgraph">[docs]</a>    <span class="k">def</span> <span class="nf">bind_vectors2BLTgraph</span><span class="p">(</span><span class="bp">self</span><span class="p">):</span>
        <span class="s">&quot;bind vectors to the curves in the BLT graph&quot;</span>
        <span class="c"># each curve has its own color:</span>
        <span class="n">colors</span> <span class="o">=</span> <span class="p">[</span><span class="s">&#39;red&#39;</span><span class="p">,</span><span class="s">&#39;blue&#39;</span><span class="p">,</span><span class="s">&#39;green&#39;</span><span class="p">,</span><span class="s">&#39;black&#39;</span><span class="p">,</span><span class="s">&#39;grey&#39;</span><span class="p">,</span>
                  <span class="s">&#39;black&#39;</span><span class="p">,</span><span class="s">&#39;yellow&#39;</span><span class="p">,</span><span class="s">&#39;orange&#39;</span><span class="p">]</span>
        <span class="k">if</span> <span class="nb">len</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">funcs</span><span class="p">)</span> <span class="o">&gt;</span> <span class="nb">len</span><span class="p">(</span><span class="n">colors</span><span class="p">):</span>
            <span class="k">print</span> <span class="s">&quot;Cannot handle more than </span><span class="si">%d</span><span class="s"> functions&quot;</span>\
                  <span class="o">%</span> <span class="nb">len</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">funcs</span><span class="p">);</span> <span class="n">sys</span><span class="o">.</span><span class="n">exit</span><span class="p">(</span><span class="mi">1</span><span class="p">)</span>
        <span class="n">color_counter</span> <span class="o">=</span> <span class="mi">0</span>
        <span class="k">for</span> <span class="n">curvename</span> <span class="ow">in</span> <span class="bp">self</span><span class="o">.</span><span class="n">funcs</span><span class="p">:</span>
            <span class="k">if</span> <span class="bp">self</span><span class="o">.</span><span class="n">g</span><span class="o">.</span><span class="n">element_exists</span><span class="p">(</span><span class="n">curvename</span><span class="p">):</span>
                <span class="bp">self</span><span class="o">.</span><span class="n">g</span><span class="o">.</span><span class="n">element_delete</span><span class="p">(</span><span class="n">curvename</span><span class="p">)</span>
            <span class="bp">self</span><span class="o">.</span><span class="n">g</span><span class="o">.</span><span class="n">line_create</span><span class="p">(</span>
                <span class="n">curvename</span><span class="p">,</span>           <span class="c"># used as identifier</span>
                <span class="n">xdata</span><span class="o">=</span><span class="nb">tuple</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">x</span><span class="p">),</span>            <span class="c"># x coords</span>
                <span class="n">ydata</span><span class="o">=</span><span class="nb">tuple</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">y</span><span class="p">[</span><span class="n">curvename</span><span class="p">]),</span> <span class="c"># y coords</span>
                <span class="n">color</span><span class="o">=</span><span class="n">colors</span><span class="p">[</span><span class="n">color_counter</span><span class="p">],</span>
                <span class="n">linewidth</span><span class="o">=</span><span class="mi">1</span><span class="p">,</span>
                <span class="n">dashes</span><span class="o">=</span><span class="s">&#39;&#39;</span><span class="p">,</span>           <span class="c"># number: dash, &quot;&quot;: solid</span>
                <span class="n">label</span><span class="o">=</span><span class="n">curvename</span><span class="p">,</span>     <span class="c"># legend</span>
                <span class="n">symbol</span><span class="o">=</span><span class="s">&#39;&#39;</span><span class="p">,</span>           <span class="c"># no symbols at data points</span>
                <span class="p">)</span>
            <span class="n">color_counter</span> <span class="o">+=</span> <span class="mi">1</span>
</div>
<div class="viewcode-block" id="FuncDependenceViz.visualize"><a class="viewcode-back" href="../../TkGUI.html#scitools.TkGUI.FuncDependenceViz.visualize">[docs]</a>    <span class="k">def</span> <span class="nf">visualize</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">var</span><span class="p">):</span>
        <span class="k">for</span> <span class="n">pname</span> <span class="ow">in</span> <span class="bp">self</span><span class="o">.</span><span class="n">p</span><span class="p">:</span>
            <span class="bp">self</span><span class="o">.</span><span class="n">p</span><span class="p">[</span><span class="n">pname</span><span class="p">]</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">slider_var</span><span class="p">[</span><span class="n">pname</span><span class="p">]</span><span class="o">.</span><span class="n">get</span><span class="p">()</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">make_vectors</span><span class="p">()</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">fill_vectors</span><span class="p">()</span>

        <span class="n">title</span> <span class="o">=</span> <span class="s">&quot;&quot;</span>
        <span class="k">for</span> <span class="n">pname</span> <span class="ow">in</span> <span class="bp">self</span><span class="o">.</span><span class="n">p</span><span class="p">:</span>
            <span class="n">title</span>  <span class="o">+=</span> <span class="s">&quot;</span><span class="si">%s</span><span class="s">=</span><span class="si">%g</span><span class="s"> &quot;</span> <span class="o">%</span> <span class="p">(</span><span class="n">pname</span><span class="p">,</span><span class="bp">self</span><span class="o">.</span><span class="n">p</span><span class="p">[</span><span class="n">pname</span><span class="p">])</span>

        <span class="k">if</span> <span class="bp">self</span><span class="o">.</span><span class="n">viztool</span> <span class="o">==</span> <span class="s">&quot;gnuplot&quot;</span><span class="p">:</span>
            <span class="bp">self</span><span class="o">.</span><span class="n">g</span><span class="o">.</span><span class="n">clear</span><span class="p">()</span>
            <span class="bp">self</span><span class="o">.</span><span class="n">g</span><span class="p">(</span><span class="s">&quot;set xrange [</span><span class="si">%g</span><span class="s">:</span><span class="si">%g</span><span class="s">]&quot;</span> <span class="o">%</span> <span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">xmin</span><span class="o">.</span><span class="n">get</span><span class="p">(),</span>
                                           <span class="bp">self</span><span class="o">.</span><span class="n">xmax</span><span class="o">.</span><span class="n">get</span><span class="p">()))</span>
            <span class="bp">self</span><span class="o">.</span><span class="n">g</span><span class="o">.</span><span class="n">title</span><span class="p">(</span><span class="n">title</span><span class="p">)</span>
            <span class="c"># we do not launch the plot here</span>
            <span class="n">plots</span> <span class="o">=</span> <span class="p">[];</span> <span class="n">line_counter</span><span class="o">=</span><span class="mi">1</span>
            <span class="k">for</span> <span class="n">funcname</span> <span class="ow">in</span> <span class="bp">self</span><span class="o">.</span><span class="n">funcs</span><span class="p">:</span>
                <span class="n">plots</span><span class="o">.</span><span class="n">append</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">Gnuplot</span><span class="o">.</span><span class="n">Data</span><span class="p">(</span>
                    <span class="bp">self</span><span class="o">.</span><span class="n">x</span><span class="p">,</span> <span class="bp">self</span><span class="o">.</span><span class="n">y</span><span class="p">[</span><span class="n">funcname</span><span class="p">],</span>
                    <span class="n">with_</span><span class="o">=</span><span class="s">&quot;line </span><span class="si">%d</span><span class="s">&quot;</span> <span class="o">%</span> <span class="n">line_counter</span><span class="p">))</span>
                <span class="n">line_counter</span> <span class="o">+=</span> <span class="mi">1</span>
            <span class="bp">self</span><span class="o">.</span><span class="n">g</span><span class="o">.</span><span class="n">plot</span><span class="p">(</span><span class="o">*</span><span class="nb">tuple</span><span class="p">(</span><span class="n">plots</span><span class="p">))</span>
        <span class="k">elif</span> <span class="bp">self</span><span class="o">.</span><span class="n">viztool</span> <span class="o">==</span> <span class="s">&quot;Pmw.Blt.Graph&quot;</span><span class="p">:</span>
            <span class="c"># BLT graph commands:</span>
            <span class="bp">self</span><span class="o">.</span><span class="n">g</span><span class="o">.</span><span class="n">xaxis_configure</span><span class="p">(</span><span class="nb">min</span><span class="o">=</span><span class="bp">self</span><span class="o">.</span><span class="n">xmin</span><span class="o">.</span><span class="n">get</span><span class="p">(),</span>
                                   <span class="nb">max</span><span class="o">=</span><span class="bp">self</span><span class="o">.</span><span class="n">xmax</span><span class="o">.</span><span class="n">get</span><span class="p">())</span>
            <span class="k">for</span> <span class="n">curvename</span> <span class="ow">in</span> <span class="bp">self</span><span class="o">.</span><span class="n">funcs</span><span class="p">:</span>
                <span class="bp">self</span><span class="o">.</span><span class="n">g</span><span class="o">.</span><span class="n">element_configure</span><span class="p">(</span>
                    <span class="n">curvename</span><span class="p">,</span> <span class="n">ydata</span><span class="o">=</span><span class="nb">tuple</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">y</span><span class="p">[</span><span class="n">curvename</span><span class="p">]))</span>
            <span class="bp">self</span><span class="o">.</span><span class="n">g</span><span class="o">.</span><span class="n">update</span><span class="p">()</span>
            <span class="bp">self</span><span class="o">.</span><span class="n">g</span><span class="o">.</span><span class="n">configure</span><span class="p">(</span><span class="n">title</span><span class="o">=</span><span class="n">title</span><span class="p">)</span>
</div>
<div class="viewcode-block" id="FuncDependenceViz.fill_vectors"><a class="viewcode-back" href="../../TkGUI.html#scitools.TkGUI.FuncDependenceViz.fill_vectors">[docs]</a>    <span class="k">def</span> <span class="nf">fill_vectors</span><span class="p">(</span><span class="bp">self</span><span class="p">):</span>
        <span class="k">for</span> <span class="n">funcname</span> <span class="ow">in</span> <span class="bp">self</span><span class="o">.</span><span class="n">funcs</span><span class="p">:</span>
            <span class="c"># slow loop over NumPy array...</span>
            <span class="k">for</span> <span class="n">i</span> <span class="ow">in</span> <span class="nb">range</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">n</span><span class="o">.</span><span class="n">get</span><span class="p">()):</span>
                <span class="n">x</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">x</span><span class="p">[</span><span class="n">i</span><span class="p">]</span>
                <span class="bp">self</span><span class="o">.</span><span class="n">y</span><span class="p">[</span><span class="n">funcname</span><span class="p">][</span><span class="n">i</span><span class="p">]</span> <span class="o">=</span> \
                     <span class="bp">self</span><span class="o">.</span><span class="n">funcs</span><span class="p">[</span><span class="n">funcname</span><span class="p">](</span><span class="n">x</span><span class="p">,</span> <span class="bp">self</span><span class="o">.</span><span class="n">p</span><span class="p">)</span>


</div></div>
<span class="k">def</span> <span class="nf">_test_FuncDependenceViz</span><span class="p">():</span>
    <span class="kn">import</span> <span class="nn">math</span>
    <span class="n">p_intervals</span> <span class="o">=</span> <span class="p">{</span><span class="s">&#39;mu&#39;</span><span class="p">:</span> <span class="p">(</span><span class="mi">0</span><span class="p">,</span><span class="mi">8</span><span class="p">),</span> <span class="s">&#39;sigma&#39;</span><span class="p">:</span> <span class="p">(</span><span class="mi">0</span><span class="p">,</span><span class="mi">1</span><span class="p">),</span> <span class="s">&#39;alpha&#39;</span><span class="p">:</span> <span class="p">(</span><span class="mi">0</span><span class="p">,</span><span class="mi">1</span><span class="p">)}</span>

    <span class="c"># recall that lambda is a reserved keyword in Python,</span>
    <span class="c"># use lambda_ instead:</span>
    <span class="k">def</span> <span class="nf">lognormal</span><span class="p">(</span><span class="n">x</span><span class="p">,</span> <span class="n">lambda_</span><span class="p">,</span> <span class="n">zeta</span><span class="p">):</span>
        <span class="k">if</span> <span class="n">x</span> <span class="o">&lt;</span> <span class="mf">1.0E-9</span><span class="p">:</span>
            <span class="n">f</span> <span class="o">=</span> <span class="mf">0.0</span>
        <span class="k">else</span><span class="p">:</span>
            <span class="n">f</span> <span class="o">=</span> <span class="mi">1</span><span class="o">/</span><span class="p">(</span><span class="n">zeta</span><span class="o">*</span><span class="n">math</span><span class="o">.</span><span class="n">sqrt</span><span class="p">(</span><span class="mi">2</span><span class="o">*</span><span class="n">math</span><span class="o">.</span><span class="n">pi</span><span class="p">)</span><span class="o">*</span><span class="n">x</span><span class="p">)</span><span class="o">*</span><span class="n">math</span><span class="o">.</span><span class="n">exp</span><span class="p">(</span>
                <span class="o">-</span><span class="mf">0.5</span><span class="o">*</span><span class="p">((</span><span class="n">math</span><span class="o">.</span><span class="n">log</span><span class="p">(</span><span class="n">x</span><span class="p">)</span><span class="o">-</span><span class="n">lambda_</span><span class="p">)</span><span class="o">/</span><span class="n">zeta</span><span class="p">)</span><span class="o">**</span><span class="mi">2</span><span class="p">)</span>
        <span class="k">return</span> <span class="n">f</span>

    <span class="k">def</span> <span class="nf">U</span><span class="p">(</span><span class="n">x</span><span class="p">,</span> <span class="n">p</span><span class="p">):</span>
        <span class="n">mu</span> <span class="o">=</span> <span class="n">p</span><span class="p">[</span><span class="s">&#39;mu&#39;</span><span class="p">];</span> <span class="n">sigma</span> <span class="o">=</span> <span class="n">p</span><span class="p">[</span><span class="s">&#39;sigma&#39;</span><span class="p">]</span>
        <span class="n">zeta</span> <span class="o">=</span> <span class="n">math</span><span class="o">.</span><span class="n">sqrt</span><span class="p">(</span><span class="n">math</span><span class="o">.</span><span class="n">log</span><span class="p">(</span><span class="mi">1</span> <span class="o">+</span> <span class="p">(</span><span class="n">sigma</span><span class="o">/</span><span class="n">mu</span><span class="p">)</span><span class="o">**</span><span class="mi">2</span><span class="p">))</span>
        <span class="n">lambda_</span> <span class="o">=</span> <span class="n">math</span><span class="o">.</span><span class="n">log</span><span class="p">(</span><span class="n">mu</span><span class="p">)</span> <span class="o">-</span> <span class="mf">0.5</span><span class="o">*</span><span class="mf">0.5</span><span class="o">*</span><span class="n">zeta</span><span class="o">**</span><span class="mi">2</span>
        <span class="k">return</span> <span class="n">lognormal</span><span class="p">(</span><span class="n">x</span><span class="p">,</span> <span class="n">lambda_</span><span class="p">,</span> <span class="n">zeta</span><span class="p">)</span>

    <span class="k">def</span> <span class="nf">F</span><span class="p">(</span><span class="n">x</span><span class="p">,</span> <span class="n">p</span><span class="p">):</span>
        <span class="n">mu</span> <span class="o">=</span> <span class="n">p</span><span class="p">[</span><span class="s">&#39;mu&#39;</span><span class="p">];</span> <span class="n">sigma</span> <span class="o">=</span> <span class="n">p</span><span class="p">[</span><span class="s">&#39;mu&#39;</span><span class="p">];</span> <span class="n">alpha</span> <span class="o">=</span> <span class="n">p</span><span class="p">[</span><span class="s">&#39;alpha&#39;</span><span class="p">]</span>
        <span class="n">zeta</span> <span class="o">=</span> <span class="n">math</span><span class="o">.</span><span class="n">sqrt</span><span class="p">(</span><span class="n">math</span><span class="o">.</span><span class="n">log</span><span class="p">(</span><span class="mi">1</span> <span class="o">+</span> <span class="p">(</span><span class="n">sigma</span><span class="o">/</span><span class="n">mu</span><span class="p">)</span><span class="o">**</span><span class="mi">2</span><span class="p">))</span>
        <span class="n">lambda_</span> <span class="o">=</span> <span class="n">math</span><span class="o">.</span><span class="n">log</span><span class="p">(</span><span class="n">mu</span><span class="p">)</span> <span class="o">-</span> <span class="mf">0.5</span><span class="o">*</span><span class="mf">0.5</span><span class="o">*</span><span class="n">zeta</span><span class="o">**</span><span class="mi">2</span>
        <span class="c"># response modification:</span>
        <span class="n">lambda_</span> <span class="o">=</span> <span class="n">math</span><span class="o">.</span><span class="n">log</span><span class="p">(</span><span class="n">alpha</span><span class="p">)</span> <span class="o">+</span> <span class="mi">2</span><span class="o">*</span><span class="n">lambda_</span>
        <span class="n">zeta</span> <span class="o">=</span> <span class="mi">2</span><span class="o">*</span><span class="n">zeta</span>
        <span class="k">return</span> <span class="n">lognormal</span><span class="p">(</span><span class="n">x</span><span class="p">,</span> <span class="n">lambda_</span><span class="p">,</span> <span class="n">zeta</span><span class="p">)</span>

    <span class="n">f</span> <span class="o">=</span> <span class="p">{</span> <span class="s">&#39;U&#39;</span><span class="p">:</span> <span class="n">U</span><span class="p">,</span> <span class="s">&#39;F&#39;</span><span class="p">:</span> <span class="n">F</span> <span class="p">}</span>   <span class="c"># function names and objects</span>

    <span class="n">root</span> <span class="o">=</span> <span class="n">Tkinter</span><span class="o">.</span><span class="n">Tk</span><span class="p">()</span>
    <span class="n">Pmw</span><span class="o">.</span><span class="n">initialise</span><span class="p">(</span><span class="n">root</span><span class="p">)</span>
    <span class="k">try</span><span class="p">:</span>
        <span class="n">viztool</span> <span class="o">=</span> <span class="n">sys</span><span class="o">.</span><span class="n">argv</span><span class="p">[</span><span class="mi">1</span><span class="p">]</span>
    <span class="k">except</span><span class="p">:</span>
        <span class="n">viztool</span> <span class="o">=</span> <span class="s">&#39;gnuplot&#39;</span>  <span class="c"># alternative: Pmw.Blt.Graph</span>
    <span class="k">try</span><span class="p">:</span>
        <span class="n">update</span> <span class="o">=</span> <span class="n">sys</span><span class="o">.</span><span class="n">argv</span><span class="p">[</span><span class="mi">2</span><span class="p">]</span>
    <span class="k">except</span><span class="p">:</span>
        <span class="n">update</span> <span class="o">=</span> <span class="s">&#39;after&#39;</span>  <span class="c"># alternative: arbitrary (cont. update)</span>
    <span class="n">gui</span> <span class="o">=</span> <span class="n">FuncDependenceViz</span><span class="p">(</span><span class="n">root</span><span class="p">,</span> <span class="n">p_intervals</span><span class="p">,</span> <span class="n">f</span><span class="p">,</span>
                            <span class="n">xmin</span><span class="o">=</span><span class="mi">0</span><span class="p">,</span> <span class="n">xmax</span><span class="o">=</span><span class="mi">8</span><span class="p">,</span>
                            <span class="n">resolution</span><span class="o">=</span><span class="mi">40</span><span class="p">,</span>
                            <span class="n">viztool</span><span class="o">=</span><span class="n">viztool</span><span class="p">,</span>
                            <span class="n">plot_update</span><span class="o">=</span><span class="n">update</span><span class="p">)</span>
    <span class="n">root</span><span class="o">.</span><span class="n">mainloop</span><span class="p">()</span>


<span class="k">def</span> <span class="nf">_test</span><span class="p">():</span>
    <span class="k">print</span> <span class="s">&#39;Testing DrawFunction:&#39;</span>
    <span class="n">_test_DrawFunction</span><span class="p">()</span>
    <span class="k">print</span> <span class="s">&#39;Testing CanvasCoords:&#39;</span>
    <span class="n">_CanvasCoords_test</span><span class="p">()</span>
    <span class="k">print</span> <span class="s">&#39;Testing FunctionSelector:&#39;</span>
    <span class="n">_FunctionSelector_test</span><span class="p">()</span>
    <span class="k">print</span> <span class="s">&#39;Testing ParameterInterface:&#39;</span>
    <span class="n">_test1_Parameters</span><span class="p">()</span>
    <span class="n">_test1_Parameters_wGUI</span><span class="p">()</span>
    <span class="k">print</span> <span class="s">&#39;Testing FuncDependenceViz:&#39;</span>
    <span class="n">_test_FuncDependenceViz</span><span class="p">()</span>

<span class="k">if</span> <span class="n">__name__</span> <span class="o">==</span> <span class="s">&#39;__main__&#39;</span><span class="p">:</span>
    <span class="n">_test</span><span class="p">()</span>
</pre></div>

          </div>
        </div>
      </div>
      <div class="sphinxsidebar">
        <div class="sphinxsidebarwrapper">
            <p class="logo"><a href="../../index.html">
              <img class="logo" src="../../_static/scitools_logo.jpg" alt="Logo"/>
            </a></p>
<div id="searchbox" style="display: none">
  <h3>Quick search</h3>
    <form class="search" action="../../search.html" method="get">
      <input type="text" name="q" />
      <input type="submit" value="Go" />
      <input type="hidden" name="check_keywords" value="yes" />
      <input type="hidden" name="area" value="default" />
    </form>
    <p class="searchtip" style="font-size: 90%">
    Enter search terms or a module, class or function name.
    </p>
</div>
<script type="text/javascript">$('#searchbox').show(0);</script>
        </div>
      </div>
      <div class="clearer"></div>
    </div>
    <div class="related">
      <h3>Navigation</h3>
      <ul>
        <li class="right" style="margin-right: 10px">
          <a href="../../genindex.html" title="General Index"
             >index</a></li>
        <li class="right" >
          <a href="../../py-modindex.html" title="Python Module Index"
             >modules</a> |</li>
        <li class="right" >
          <a href="../../np-modindex.html" title="Python Module Index"
             >modules</a> |</li>
        <li><a href="../../index.html">SciTools 0.9.0 documentation</a> &raquo;</li>
          <li><a href="../index.html" >Module code</a> &raquo;</li> 
      </ul>
    </div>
    <div class="footer">
        &copy; Copyright 2012, H. P. Langtangen, J. Ring, ++.
      Created using <a href="http://sphinx.pocoo.org/">Sphinx</a> 1.1.2.
    </div>
  </body>
</html>